我正在尝试创建一个具有两个不同的主面板和侧面板的 Shiny 网页。因此,当在sidebarPanel中选择“案例A”时,我想要具有特定tabsetPanel的特定mainPanel,如果我选择“案例B”,则将有所不同。阅读文档后,我陷入了这一点:

ui.R:

shinyUI(pageWithSidebar(
  headerPanel("This is a Shiny page"),
  sidebarPanel(
     selectInput(
        "plotType", "Plot Type",
        c("Case A","Case B")
         )
  ),
  mainPanel(
    conditionalPanel(
      condition(input.plotType == 'Case A'),
       tabsetPanel(
         tabPanel("A1",
           textOutput("This is conditionalPanel A1")
                  ),
         tabPanel("A2",
           textOutput("This is conditionalPanel A2")
                  )
         )
     ),
    conditionalPanel(
      condition(input.plotType == 'Case B'),
      tabsetPanel(
        tabPanel("B1",
          textOutput("This is conditionalPanel B1")
                  ),
        tabPanel("B2",
          textOutput("This is conditionalPanel B2")
                  )
      )
    )
  )
))

server.R:
shinyServer(function(input, output) {
})

我收到此错误:
Listening on port 50709
Error in tag("div", list(...)) : could not find function "condition"
Calls: runApp ... tag -> conditionalPanel -> div -> <Anonymous> -> tag
Error in setwd(orig.wd) : cannot change working directory
Calls: runApp ... conditionalPanel -> div -> <Anonymous> -> tag -> setwd
Execution halted

有什么想法我想念的吗?

最佳答案

事实证明,我正在使用此命名法作为示例:

condition(input.plotType == 'Case B')

而如果我将其更改为此,则它可以工作:
condition = "input.plotType=='Case B'"

关于Rstudio Shiny 的conditionalPanel用于mainPanel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19724022/

10-13 02:22