本文介绍了R Shinydashboard基于选项卡选择显示/隐藏UI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人可以提供帮助,我正在努力争取一项要求。我必须根据用户对选项板的选择来显示/隐藏Dashboardsidebar上的某些元素。这是UI代码的一部分,可让您大致了解我的应用程序的结构。我只需要在tabpPanel 2上显示第四输出,第五输出和下载按钮。

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

    )
  )
)

感谢,
Manoj Agrawal

thanks,Manoj Agrawal

推荐答案

您必须设置 id tabsetPanel 以及每个 tabPanel 的值,然后可以使用 conditionalPanel 中的> input.tabsetId 隐藏/显示按钮:

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

这篇关于R Shinydashboard基于选项卡选择显示/隐藏UI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:42