从R中的renderUI访问输入时出现问题
我是Shiny的新手,但我正在开发一款需要在UI和shinyServer之间来回切换的应用程序。为此,我已经熟悉了DynamicRenderui函数。但是,我在正确处理通过renderUI函数发送到UI的输入时遇到了一些问题 我已经编写了一个关于我的问题的快速玩具示例从R中的renderUI访问输入时出现问题,r,user-interface,ggplot2,shiny,R,User Interface,Ggplot2,Shiny,我是Shiny的新手,但我正在开发一款需要在UI和shinyServer之间来回切换的应用程序。为此,我已经熟悉了DynamicRenderui函数。但是,我在正确处理通过renderUI函数发送到UI的输入时遇到了一些问题 我已经编写了一个关于我的问题的快速玩具示例 library(shiny) ui <- fluidPage( numericInput("cat.count", "How many cats do you have?", min = 0, value = 0), ch
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)
库(闪亮)
像这样的工作
rm(list = ls())
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(is.null(input$pet.check)){return()}
if(input$pet.check){
return(checkboxInput("dog.check", "Do you have dogs?", value = FALSE))
}
})
output$dog.num <- renderUI({
if(is.null(input$dog.check)){return()}
numericInput("dog.count", "How many dogs do you have?", min = 1, value = 0)
})
})
runApp(list(ui = ui, server = server))
rm(list=ls())
图书馆(闪亮)
ui如果您键入以下语句
A(x) & B(x)
在R
中,即使A(x)
错误,A
和B
也会得到评估。这就是你的错误的来源。因此,如果像猪排的答案中那样的
语句不完全符合我的想法,那么最好使用嵌套的,但是您的代码帮助很大。谢谢,猪排和@Gregor