【发布时间】:2018-12-04 22:46:28
【问题描述】:
在我的闪亮应用程序中,我有很多 valueBoxes,每个代表闪亮仪表板侧边栏中的 tabItem。单击 valueBox 时,页面应移动到正确的选项卡。
我没有多次复制粘贴代码,而是编写了一个可重用模块,该模块呈现 valueBox 并将 valueBox 的类更改为 actionButton。在服务器部分中,我包含了一个 observeEvent,它在单击 valueBox 时调用 updateTabItems。但是当点击什么都没有发生。该模块似乎无法操作仪表板侧边栏。
library(shiny)
library(shinydashboard)
value_box_output <- function(.id) {
ns <- NS(.id)
valueBoxOutput(ns("overview.box"))
}
value_box <- function(input, output, session, .value, .subtitle, .tab.name) {
ns <- session$ns
output$overview.box <- renderValueBox({
box1 <- valueBox(
.value,
.subtitle,
href = "#",
width = NULL
)
box1$children[[1]]$attribs$class <- "action-button"
box1$children[[1]]$attribs$id <- ns("button")
box1
})
observeEvent(input$button, {
print("clicked")
updateTabItems(session, inputId = "tabs", selected = .tab.name)
})
}
ui <- dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem("Overview", tabName = "Overview"),
menuItem("Tab 1", tabName = "Tab_1")
)
),
dashboardBody(
tabItems(
tabItem("Overview", value_box_output("tab")),
tabItem("Tab_1")
)
)
)
server <- function(input, output, session) {
callModule(value_box,
"tab",
.value = 33,
.subtitle = "Tab 1",
.tab.name = "Tab_1")
}
shinyApp(ui, server)
【问题讨论】:
标签: r shiny shinydashboard