R Shinydashboard Showing/Hiding UI Elements based on Tab selection

[亡魂溺海] 提交于 2019-12-07 05:57:00

问题


I am struggling with a requirement if someone can help. I have to show/hide some elements on the Dashboardsidebar based on the tabpanel selection by the user. Here is part of the UI code to give you an idea of the structure of my app. I need to show fourthoutput, fifthout and download button only on tabpPanel 2.

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"))
      )

    )
  )
)

thanks, Manoj Agrawal


回答1:


You have to set an id to the tabsetPanel and a value to each tabPanel. Then you can use input.tabsetId in conditionalPanel to hide/show the button:

...
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",
...


来源:https://stackoverflow.com/questions/39987908/r-shinydashboard-showing-hiding-ui-elements-based-on-tab-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!