2
votes

I am using shiny modules with some charts and everything works fine (amazing functionality!), ... but I can not make them work with valueBox (from shinydashboard). Nothing is rendered... Here is a minimal example:

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)

In the given example parameteres "number" and "metric" are explicitly provided, but my intention is they will be defined as variables of a dataframe.

Any help will be welcome!!! (sorry my english)

1
Have you tried using renderUI() instead of renderValueBox? It's a workaround, but it might solve your problem.thisislammers
No succes using renderUI.COLO

1 Answers

3
votes

You need to use ns() in all your defined Module inputs. The module server is taking the members of the output vector and will internally attach the module ID to them ("tile_1" and "tile_2" in your case) - this is what you need to do manually in UI by using ns(). So if you just change your module UI output definition to the following, your code will work:

valueBoxOutput(ns("tile1"), width=12)

enter image description here