我使用conditionalpanels动态构建我的Shiny应用程序。看起来面板所基于的条件在启动时不会被评估。默认情况下,该面板可见,并且仅在某些操作后消失。面板是可见的,即使条件不满足(input.select1.length = 0,小于1 ......)。
最小的工作示例:
Server.R:
2_147_483_646
UI.R:
shinyServer(function(input, output,session){
output$selectInput1 <- renderUI({
selectInput(
inputId = "select1",
label = "Select",
choices = c('1','2','3'),
selected = NULL,
multiple = TRUE
)
})
})
答案 0 :(得分:0)
正如@porkchop指出的那样,你可以在server.R
的renderUI函数中创建条件:
Server.R:
shinyServer(function(input, output,session){
output$selectInput1 <- renderUI({
selectInput(
inputId = "select1",
label = "Select",
choices = c('1','2','3'),
selected = NULL,
multiple = TRUE
)
})
output$panel1 <- renderUI({
if(!is.null(input$select1) && length(input$select1) > 0){
condition1 = 'true'
} else {
condition1 = 'false'
}
conditionalPanel(
condition1,
p('hi')
)
})
})
UI.R:
dashboardPage(
title = "",
## Header content + dropdownMenu
dashboardHeader(
title = tags$b(""),
titleWidth = 250
),
## Sidebar content
dashboardSidebar(
width = 250,
sidebarMenu(
id = "tabs",
menuItem("tab1", tabName = "tab", icon = icon("table"))
)
),
## Body content
dashboardBody(
tabItems(
tabItem(tabName = "tab",
div(
div(
style="float: left; padding-left: 20px; padding-right: 20px; width: 350px; background-color: #F4F4F4; height: calc(100vh - 50px) !important;",
uiOutput('selectInput1')
),
div(
uiOutput('panel1')
)
)
)
)
)
)