You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Shiny应用侧边栏标签选择实现条件输出的报错解决

解决Shiny中object 'input.tabs' not found报错问题

这个报错的核心原因是你在conditionalPanel的condition参数里用了R语法,但这个参数要求的是JavaScript表达式——Shiny的UI层在渲染时会用JS来判断条件,而非R代码。

具体修正步骤

把conditionalPanel里的条件判断改成JS的语法规则,并且用引号把整个表达式包裹起来:

  • 针对「otu」标签的条件:"input.tabs === 'otu'"
  • 针对「anova」标签的条件:"input.tabs === 'anova'"

修改后的完整UI代码

ui <- fluidPage(
  # Make a title to display in the app
  titlePanel(" Exploring the Effect of Metarhizium on the Soil and Root Microbiome "),
  # Make the Sidebar layout
  sidebarLayout(
    # Put in the sidebar all the input functions
    sidebarPanel(
      tabsetPanel(id="tabs",
                  tabPanel("otu","OTU selection",
                           selectInput('dataset', 'dataset', names(abundance_tables)),
                           uiOutput("otu"),
                           br(),
                           # Add comment
                           p("For details on OTU identification please refer to the original publications")),
                  tabPanel("anova","anova",
                           sliderInput('pval','p-value for significance', value=5,min=0,max=0.5,step=0.00001),
                           selectInput('fact_ofInt','factor of interest',FactorsOfInt))
      )
    ),
    # Put in the main panel of the layout the output functions
    mainPanel(
      conditionalPanel(condition = "input.tabs === 'otu'",
                       plotOutput('plot')
                       # dataTableOutput("table")
                       ),
      conditionalPanel(condition = "input.tabs === 'anova'",
                       plotOutput('plot2')
                       # dataTableOutput("table")
                       )
    )
  )
)

补充说明

  • 在conditionalPanel中,input是前端JS层面的对象,必须遵循JS语法(比如用===做严格相等判断,字符串用单/双引号包裹)
  • 整个条件表达式必须是字符串格式,这样Shiny才会将其传递给前端JS执行判断逻辑

内容的提问来源于stack exchange,提问作者user2814482

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:48:10