【问题标题】:Rshiny ConditionalPanel displaying both conditionsR Shiny ConditionalPanel 显示两个条件
【发布时间】:2019-09-20 10:43:06
【问题描述】:

我对闪亮还很陌生,遇到过其他人遇到过的问题,但我似乎找不到解决方案。我的 Rshiny 应用程序中的条件面板显示了我的所有条件。我参考了以下链接,甚至尝试了 renderUI 解决方案,但没有运气。这似乎是一个我只是想念的简单问题,但任何帮助、条件面板的替代解决方案或对问题所在位置的见解将不胜感激!

(然后使用框中的值来更新图表,当我在我的应用程序中使用此解决方案时,图表也不再显示。我可以共享多少其他代码受到限制)

R shiny conditionalPanel displaying both conditions

To add the values in dynamically created textBox in RShiny

Producing dynamic/multiple input boxes to collect data depending on user selection in Shiny R

runApp(list(
  ui = bootstrapPage(
    selectInput("ctype","test:" , c("F", "S"), selected = F),
    conditionalPanel("input.ctype == 'F'",
                     numericInput("comp", "Box 1", value =  100),
                     numericInput("comp1", "Box 2", value =  200),
                     numericInput("comp2", "Box3", value = 300),
                     actionButton("revert", "Back", icon = icon("history"))

    ),
    conditionalPanel("input.ctype == 'S",
                     numericInput("comp3", "Box 4", value = 0))

  ),
  server = function(input, output) {
    output$plot <- renderPlot({ hist(runif(input$n)) })
  }
))

下面是当前的输出。我需要的是,只选择“f”,只有“框1”,“框2”,“框3”和“返回”出现不是 EM>“框4”强>。仅出现“s”时选择“box 4”。

【问题讨论】:

  • 你想要的输出是什么?
  • 已编辑以进一步解释所需的输出@JohanRosa
  • 在@Shawn Fries 的建议下,这可能是一个简单的小代码错误

标签: r shiny conditional


【解决方案1】:

第二个条件面板的条件中缺少一个结束撇号。如果你把它加回去,它会像写的那样工作。

【讨论】:

  • 欢迎来到 SO!详细说明你的答案 - 例如,在你的答案中包含一行正确的代码。否则,这里的一些老年人可能会删除这些内容,因为他们会检查简短且低质量的答案。
【解决方案2】:

我使用了 renderUI 选项

runApp(list(
  ui = bootstrapPage(
    selectInput("ctype","test:" , c("F", "S"), selected = F),
    uiOutput("comp")


  ),
  server = function(input, output) {

    output$comp <- renderUI({

      if(input$ctype == "F"){

        conditions <- list( fluidRow(
          column(numericInput("comp", "Box 1", value =  100), width = 2),
          column(numericInput("comp1", "Box 2", value =  200), width = 2),
          column(numericInput("comp2", "Box3", value = 300), width = 2)),
          actionButton("revert", "Back", icon = icon("history")))

      }

      if(input$ctype == "S") {

        conditions <-  numericInput("comp3", "Box 4", value = 0)

      }

      return(conditions)
    })

    output$plot <- renderPlot({ hist(runif(input$n)) })
  }
))


【讨论】:

  • 非常感谢@johan!这正是我正在寻找的!.....作为后续行动,如果我想绘制盒子,彼此相邻而不是堆叠,那将在服务器或 ui 中完成(我不在 renderUI 对象中没有太多背景)?
  • fluidRow 的每个框中使用函数column()。所有这些都在server 中。我正在为你编辑答案。
猜你喜欢
  • 2014-04-13
  • 1970-01-01
  • 2018-03-09
  • 2016-02-03
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-15
相关资源
最近更新 更多