r - 如何更改主面板中每个 tabPanel 的 sidebarPanel
问题描述
我想在 Shiny 画廊 ( https://shiny.rstudio.com/gallery/radiant.html )中开发一个布局类似于 Radiant 的应用程序。在该应用程序中,sidebarPanel 会针对 mainPanel 中存在的每个 tabPanel 进行更改。这是如何实现的?这张图片显示了我的布局,我希望侧边栏面板(现在为空)根据用户选择的选项卡(元数据、原始数据、QC 数据)进行更改。是否有人知道如何执行此操作,或者您能否指出 Radiant 应用程序中的 ui 代码所在的位置?
编辑:收到下面的答案后,我将代码编辑为如下所示,而不是将侧边栏放在新功能中。但是,它还没有工作。不应该吗?还有什么问题?
ui <- navbarPage(title = "SD Mesonet Quality Control", id = "navbarPage",
tabPanel(title = 'Data',
sidebarLayout(
sidebarPanel(
conditionalPanel(condition="input.tabselected == 1",
actionButton('bt','button Tab 1')
),
conditionalPanel(condition="input.tabselected == 2",
selectInput('select','choice',choices=c("A","B"))
)
),
mainPanel(
tabsetPanel(type = "tabs", id = "tabselected",
tabPanel("Instrumentation", value = 1, plotOutput("plot")),
tabPanel("Metadata", value = 2, plotOutput("plot"))
)
)
),
)
)
server <- function(input,output){
}
shinyApp(ui,server)
解决方案
这是一个条件面板,请参阅此用例或此演示。
要回答您的问题,您可以将面板的条件链接到选项卡的 id :
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
conditionalPanel(condition="input.tabselected==1",
actionButton('bt','button Tab 1')
),
conditionalPanel(condition="input.tabselected==2",
selectInput('select','choice',choices=c("A","B"))
)
)
)
# Header ----
header <- dashboardHeader(title="Test conditional panel")
# Body ----
body <- dashboardBody(
mainPanel(
tabsetPanel(
tabPanel("tab1", value=1,
h4("Tab 1 content")),
tabPanel("tab2", value=2,
h4("Tab 2 content")),
id = "tabselected"
)
)
)
ui <- dashboardPage(header, sidebar, body)
shinyApp(ui=ui,server=server)
推荐阅读
- c# - 如何在系统托盘中的应用程序C#中创建声音通知
- scala - 通过将长度增加到 List[Int] 长度从 List[Int] 中选择子集
- azure - 在 CDN 端点(Verizon 高级版)上创建 HTTP 规则的正确 Azure CLI 命令是什么?
- c# - 有没有办法直接从 c# 代码设置 Aspose 单元格的数据类型?
- javascript - 使用 es6 模块创建自定义“事件监听器”
- mysql - MySQL - 检索与时间戳对应的行
- python - 将列名与来自不同 DataFrame 的数据相关联
- java - 接受选项时获取 ModelValidationException
- 作为查询参数
- windbg - Windbg:如何在线程执行命令中显示线程详细信息?
- git - 在提交之前执行 CHECKOUT GIT commad