Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从R中的renderUI访问输入时出现问题_R_User Interface_Ggplot2_Shiny - Fatal编程技术网

从R中的renderUI访问输入时出现问题

从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

我是Shiny的新手,但我正在开发一款需要在UI和shinyServer之间来回切换的应用程序。为此,我已经熟悉了DynamicRenderui函数。但是,我在正确处理通过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)
库(闪亮)

像这样的工作

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