R Shinydashboard Showing/Hiding UI 基于选项卡选择的元素

R Shinydashboard Showing/Hiding UI Elements based on Tab selection

如果有人可以提供帮助,我正在努力满足要求。我必须根据用户选择的选项卡面板 show/hide Dashboardsidebar 上的一些元素。这是 UI 代码的一部分,可让您了解我的应用程序的结构。我只需要在 tabpPanel 2 上显示 fourthoutput、fifthout 和下载按钮。

ui <- dashboardPage(
  dashboardHeader(title = "My App"),
  dashboardSidebar(
    width = 350,
    fileInput(
      'file1',
      'Upload Items List',
      accept = c('text/csv',
                 'text/comma-separated-values,text/plain',
                 '.csv')
    ),
    fluidRow(column(
      width = 2,
      offset = 1,
      actionButton("goButton", "Submit")
    )),
    br(),
    br(),
    uiOutput("FirstOutput"),
    uiOutput("SecondOutput"),
    uiOutput("ThirdOutput"),
    uiOutput("FourthOutput"),
    uiOutput("FifthOutput"),

      fluidRow(column(
        width = 2,
        offset = 1,
        downloadButton('downloadData', 'Download')))
  ),
  dashboardBody(
    tags$style(
      type = "text/css",
      ".shiny-output-error { visibility: hidden; }",
      ".shiny-output-error:before { visibility: hidden; }"
    ),

    tabsetPanel(
      type = "tabs",

      tabPanel("1", fluidRow(box(
        plotlyOutput("pie1")
      ),
      box(
        plotlyOutput("barplot1")
      )),
      fluidRow(box(
        plotlyOutput(outputId = "barplot2")
      ))),

      tabPanel("2",
        div(style = 'overflow-x: scroll', dataTableOutput("contents"))
      )

    )
  )
)

谢谢, 马诺吉·阿格拉瓦尔

您必须为 tabsetPanel 设置一个 id,并为每个 tabPanel 设置一个值。然后你可以在conditionalPanel中使用input.tabsetId到hide/show按钮:

...
conditionalPanel(
  condition = "input.tabs == 'show'",
  fluidRow(column(
    width = 2,
    offset = 1,
    downloadButton('downloadData', 'Download'))))
),
...

...
tabsetPanel( id="tabs",
...
tabPanel("1", value="show",
...
tabPanel("2", value="hide",
...