[英]How to change sidebarPanel for every tabPanel in the Main Panel
我想在 Shiny 畫廊 ( https://shiny.rstudio.com/gallery/radiant.html ) 中開發一個布局類似於 Radiant 的應用程序。 在該應用程序中,存在於 mainPanel 中的每個 tabPanel 的 sidebarPanel 都會發生變化。 這是如何實現的? 這張圖片顯示了我的布局,我希望 sidebarPanel(現在是空的)根據用戶選擇的選項卡(元數據、原始數據、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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.