我正在使用带有一些图表的 Shiny 模块,一切正常(令人惊叹的功能!),...但我无法使它们与 valueBox 一起使用(来自 Shiny 仪表板)。什么都没有渲染... 这是一个最小的例子:
library(shinydashboard)
# MODULE UI
bsc_tile_UI <- function(id) {
ns <- NS(id)
valueBoxOutput("tile1", width=12)
}
# MODULE Server
bsc_tile_OUT <- function(input, output, session, number, metric) {
output$tile1 <- renderValueBox({
valueBox(number, paste(metric), icon = icon("arrow-up"),color = "blue",
width=12)
})
}
ui<-dashboardPage(
dashboardHeader(title = "Dashboard"),
sidebar <- dashboardSidebar(disable = TRUE),
dashboardBody(
fluidPage(
bsc_tile_UI("tile_1"),
bsc_tile_UI("tile_2")
)
)
)
# App server
server <- function(input, output,session){
callModule(bsc_tile_OUT, "tile_1", '300', 'metric 1')
callModule(bsc_tile_OUT, "tile_2", '500', 'metric 2')
}
shinyApp(ui, server)
在给定的示例中,明确提供了参数“number”和“metric”,但我的意图是它们将被定义为数据帧的变量。
欢迎任何帮助! (对不起我的英语)
最佳答案
您需要在所有定义的模块输入中使用ns()
。模块服务器正在获取输出向量的成员,并将在内部将模块 ID 附加到它们(在您的情况下为“tile_1”和“tile_2”) - 这是您需要在 UI 中使用 ns( )
。因此,如果您只需将模块 UI 输出定义更改为以下内容,您的代码就可以工作:
valueBoxOutput(ns("tile1"), width=12)
关于r - 无法使 Shiny 模块与 valueBox 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46304314/