我有一个,如果选择是两个并且打开,tabsetPanel()我会尝试隐藏一个。我尝试使用以下代码来执行此操作,但它不起作用。tabPanel()checkbox
用户界面
shinyUI(
fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
fluidRow(
column(5,
radioButtons("radio", label = h5("Data uploaded"),
choices = list("Aff" = 1, "Cod" = 2,
"Ill" = 3),selected = 1)
)),
checkboxInput("checkbox", "cheb", value = F)
),
mainPanel(
tabsetPanel(
tabPanel("Plot", "plot1"),
conditionalPanel(
condition = "input.radio !=2 && input.checkbox == false",
tabPanel("Summary", "summary1")
),
tabPanel("Table", "table1")
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
服务器
shinyServer(function(input,output,session){
})
Run Code Online (Sandbox Code Playgroud)
我怎样才能隐藏一个tabPanel()?
您可以使用以下方法来做到这一点:在 内的列表中renderUI()创建
并有条件地添加第三个:
然后使用 返回整个列表。tabpanels()renderUI()if(input$radio == 2 & !input$checkbox)tabsetPanel()do.call(tabsetPanel, panels)
ui <- shinyUI(
fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
fluidRow(
column(5,
radioButtons("radio", label = h5("Data uploaded"),
choices = list("Aff" = 1, "Cod" = 2,
"Ill" = 3),selected = 1)
)),
checkboxInput("checkbox", "cheb", value = F)
),
mainPanel(
uiOutput("summary")
)
)
)
)
server <- shinyServer(function(input,output,session){
output$summary <- renderUI({
panels <- list(
tabPanel("Plot", "plot1"),
tabPanel("Table", "table1")
)
if(input$radio == 2 & !input$checkbox) panels[[3]] <- tabPanel("Summary", "summary1")
do.call(tabsetPanel, panels)
})
})
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3198 次 |
| 最近记录: |