我想知道为什么当我在闪亮的应用程序中打开一个页面(a1
)然后又打开另一个页面(例如a2
)时却无法回到{{ 1}}?
要重现我的示例,请按照以下步骤操作:
a1
a2
b1
c1
c8
我希望再次看到c1
的内容(“文本2的示例”),但是再次单击c1
似乎无济于事。
c1
答案 0 :(得分:2)
您的其他菜单在sidebarMenu
外部呈现,因此,选中它们时,它们的id
不会记录在输入变量input$tabs
中(应用程序正在监视该变量)。将菜单包含在sidebarMenu
中可以使tabItems
跟踪menuItems
,但是也会中断反应,即,当input$tabs == 'uci_iden'
时,其他菜单消失(因为input$tabs != 'identificacion'
)。
实现所需行为的一种方法(可能不是最佳方法)是使用server
通过renderUI
渲染其他菜单。请注意,我们仍然必须在sidebarMenu
中包含其他菜单,并通过input$tabs
对其进行监视。为确保它们在input$tabs != 'identificacion'
时停留在周围,我们可以在条件中包括它们的id
。当identification
,uni_iden
或admision_iden
均未选择时,我们将呈现一个空白的div
。
更新的代码:
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
tags$head(tags$style(
HTML('.content-wrapper { height: 1500px !important;}')
)),
hr(),
sidebarMenu(
id = "tabs",
menuItem(
"a1",
tabName = "principal",
icon = icon("pagelines"),
selected = TRUE
),
menuItem(
"a2",
icon = icon("chart-bar"),
menuSubItem("b1", tabName = "identificacion", icon = icon("angle-right")),
menuSubItem("b2", tabName = "comunicacion", icon = icon("angle-right")),
menuSubItem("b3", tabName = "medicamentos", icon = icon("angle-right")),
menuSubItem("b4", tabName = "cirugias", icon = icon("angle-right")),
menuSubItem("b5", tabName = "infecciones", icon = icon("angle-right")),
menuSubItem("b6", tabName = "caidas", icon = icon("angle-right"))
),
menuItem("a3", tabName = "procesos", icon = icon("chart-bar")),
menuItem("a4", tabName = "tiempos", icon = icon("chart-bar")),
menuItem("a5", tabName = "manual", icon = icon("mortar-board")),
menuItem("a6", tabName = "acerca", icon = icon("question")),
width = 285,
hr(),
uiOutput("more_menus")
)
)
body <- dashboardBody(tabItems(
tabItem(tabName = "principal",
withMathJax(), ("example of text")),
tabItem(tabName = "admision_iden", titlePanel("example1"), "example of text 2"),
tabItem(tabName = "uci_iden", titlePanel("example 2"), "example of text 3")
))
ui <- dashboardPage(dashboardHeader(title = "Indic", titleWidth = 285),
sidebar,
body)
server <- function(input, output) {
make_menus <- reactive({
if (req(input$tabs) %in% c("identificacion", "admision_iden", "uci_iden")) {
fluidRow(column(1),
column(
10,
menuItem(
"c1",
tabName = "admision_iden",
icon = icon("chart-line"),
selected = FALSE
),
menuItem(
"c8",
tabName = "uci_iden",
icon = icon("chart-line"),
selected = FALSE
)
))
} else {
div()
}
})
output$more_menus <- renderUI({ make_menus() })
}
runApp(list(ui = ui, server = server))