我想通过用户输入保存数据。
我将使用sprintf
它。
下面是我的代码。
用户界面
selectInput(
"ModelCB", 'Model', choices=NULL, selected = NULL, multiple = FALSE
)
服务器
shinyServer(function(input, output, session)
{
output$SelectModel <- renderText({
paste("You have selected", input$ModelCB)
GetModel <- input$ModelCB
})
TargetModelQuery <- sprintf("SELECT tb_result.mid
FROM tb_result
WHERE name='%s' and result='F'", GetModel)
})
我不能使用GetModel
。TargetModelQuery
有错误。
如何使用GetModel
?
您需要使TargetModelQuery
反应式,例如,
TargetModelQuery <- reactive({
sprintf("SELECT tb_result.mid
FROM tb_result
WHERE name='%s' and result='F'", input$ModelCB)
})
并通过调用来访问字符串TargetModelQuery()
。
完整的例子
library(shiny)
shinyApp(
shinyUI(
fluidPage(
selectInput(
"ModelCB", 'Model', choices=c("a","b","c"), selected = NULL, multiple = FALSE
),
textOutput("printStr")
)
),
shinyServer(function(input, output, session) {
TargetModelQuery <- reactive({
sprintf("SELECT tb_result.mid
FROM tb_result
WHERE name='%s' and result='F'", input$ModelCB)
})
output$printStr <- renderText({
TargetModelQuery()
})
})
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句