我正在使用conditionalPanel选项来选择要基于selectInput显示的选项卡。
当我选择“四个”时,我应该有四个选项卡,其中包括tab2,这些选项卡在选择“三个”时不可见。
问题在于选择了“四个”(Tour)选项后,tab2不会与其他视图一致。
有没有一种方法可以使用conditionalPanel并在选择“四个”而不是“三个”时使tab2出现在tab1和tab3之间?
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
selectInput(
inputId="selectTabs",
label=" Choose Number of TABS", selected = NULL,
choices=c( "Four", "Three" )),
menuItem("TABS Number", tabName = "Tabs", icon = icon("object-ungroup"))
)
),
dashboardBody(
tabItem(tabName = "Tabs",
fluidRow(
column(width=3,
box(
title="Search ",
solidHeader=TRUE,
collapsible=TRUE,
width=NULL,
textInput("textSearch", " Search ", '', placeholder = "Type keyword/statement"),
submitButton("Search")
)
),
column( width=9,
tabBox(
width="100%",
tabPanel("tab1",
htmlOutput("search1")
),
conditionalPanel("input.selectTabs === 'Four'",
tabPanel("tab2",
htmlOutput("search2")
)),
tabPanel("tab3",
htmlOutput("search3")
),
tabPanel("tab4",
htmlOutput("search4")
)
)
)
)
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
作为@annhan关于可能的重复的建议的更新,这是我的更新代码,由于我有两行Tabapanels,而不是一个动态的Tabapanels,因此它给了我不想要的输出。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
selectInput(
inputId="selectTabs",
label=" Choose Number of TABS", selected = NULL,
choices=c( "Four", "Three" )),
menuItem("TABS Number", tabName = "Tabs", icon = icon("object-ungroup"))
)
),
dashboardBody(
tabItem(tabName = "Tabs",
fluidRow(
column(width=3,
box(
title="Search ",
solidHeader=TRUE,
collapsible=TRUE,
width=NULL,
textInput("textSearch", " Search ", '', placeholder = "Type keyword/statement"),
submitButton("Search")
)
),
column( width=9,
conditionalPanel("input.selectTabs == 'Four'",
tabBox(
width="100%",
tabPanel("tab1", value=1,
htmlOutput("search1")
),
tabPanel("tab2", value=2,
htmlOutput("search2")
),
tabPanel("tab3", value=3,
htmlOutput("search3")
),
tabPanel("tab4", value=4,
htmlOutput("search4")
)
)),
conditionalPanel("input.selectTabs == 'Three' && input.selectTabs != 'Four'",
tabBox(
width="100%",
tabPanel("tab1", value=5,
htmlOutput("search1")
),
tabPanel("tab3", value=7,
htmlOutput("search3")
),
tabPanel("tab4", value=8,
htmlOutput("search4")
)
))
)))))
server <- function(input, output) {}
shinyApp(ui, server)