【发布时间】:2017-07-11 17:00:22
【问题描述】:
我是 Shiny 的新手,但我正在开发一个需要在 UI 和 shinyServer 之间来回切换的应用程序。为此,我已经熟悉了动态 renderUI 函数。但是,我在正确处理通过 renderUI 函数发送到 UI 的输入时遇到了一些问题。
我已经编写了一个关于我的问题的快速玩具示例。
library(shiny)
ui <- fluidPage(
numericInput("cat.count", "How many cats do you have?", min = 0, value = 0),
checkboxInput('pet.check',"Do you other pets?", value = FALSE),
uiOutput("dog.input"),
uiOutput("dog.num")
)
server <- shinyServer(function(input,output){
output$dog.input <- renderUI({
if(input$pet.check){
return(checkboxInput("dog.check", "Do you have dogs?", value = FALSE))
}
})
output$dog.num <- renderUI({
if (exists("input$dog.check") & input&dog.check){
return(numericInput("dog.count", "How many dogs do you have?", min = 1,
value = 0))
}
})
})
shinyApp(ui = ui,server = server)
一旦这个玩具应用程序正常运行,“最终产品”将是一个简单的条形图,通过 geom_bar 和 ggplot2 图形显示用户拥有的宠物总数。
除了 req() 和 exists() 函数之外,我还研究了很多 reactive() 函数,但到目前为止,我一直在绕圈子。
提前致谢!
【问题讨论】:
标签: r user-interface ggplot2 shiny