【发布时间】:2019-02-12 21:34:06
【问题描述】:
我正在通过比较电子邮件中发送的代码和用户提交的代码来在我的应用中构建身份验证部分。我已经尝试通过使用 react()、isolate()、renderTable() 来添加 if 语句。我要么得到值应该在反应部分错误中,要么应用程序根本没有响应。 以下是我在 Server.R 中的内容,该应用完全没有响应且没有错误。
shinyServer(function(input, output, session) {
myData <- reactive({
req(input$Id)
#connect to the database, get the data, res
#send an email with random number, rnd
list(res,rnd)
})
output$tbTable <- renderTable({req(input$Auth)
if (input$AuthCode==myData()$rnd) {
myData()$res
}
else{
as.data.frame(c("Authentication Failed"))
}
})
output$downloadData <- downloadHandler(
filename = function() {
paste(input$Id, " filname.xlsx", sep = "")
},
content = function(file) {
write.csv(myData(), file, row.names = FALSE)
}
)#this part need to depend on the if-statement as well
}
)
UI.R
ui <- shinyUI(fluidPage(title = "aaa",
titlePanel("aaa"),
sidebarLayout(
sidebarPanel(
textInput("Id", "Enter Acct Name below"),
submitButton(text="Submit"),
tags$hr(),
numericInput("AuthCode",label="Authentication",value=""),
actionButton("Auth",label="Submit"),
tags$hr(),
tags$hr(),
downloadButton("downloadData", "Download Data")
),
mainPanel(
tabsetPanel(
tabPanel("Data", tableOutput("tbTable"))
))
),
)
)
【问题讨论】:
-
你为什么用这个表达
as.data.frame(c("Authentication Failed"))? -
我不太清楚 Shiny 中的数据结构。作为 res,输出是一个数据帧,所以我将此字符串转换为数据帧以避免不匹配。如果是问题,请欣赏有关不利影响的任何意见。
-
如果有一个模态框说身份验证失败,你还好吗?
-
是的,当然。
-
为什么会有第一个提交按钮,账户和验证码不能是一个按钮吗?
标签: r shiny shiny-server shiny-reactivity