Search code examples
rshinybslib

Shiny value boxes with same textOutput disappear


It seems I can't have the same textOutput() in 2 different value boxes. I didn't mean to do this but it took me 2 hours of troubleshooting to realize what the problem is. Is there a reason this fails?

1 value box is fine:

enter image description here

2 value boxes with the same textOutput() is not.

enter image description here

If you uncomment the first section, you'll see that the reactive values disappear. I'm curious why this happens, if this is a bug, and if so, what package do I report it to?

shinyApp(
  ui = fluidPage(
    # value_box(
    #   title = "Title",
    #   value = textOutput("x"),
    #   showcase = bs_icon("rocket-takeoff-fill")
    # ),
    value_box(
      title = "Title", 
      value = textOutput("x"), 
      showcase = bs_icon("rocket-takeoff-fill")
    )
  ),
  server =  function(input, output, session) {
    output$x <- renderText({ nrow(cars) })
    output$y <- renderText({ nrow(cars) })
  }
) |>
  runApp(launch.browser = rstudioapi::viewer)

Solution

  • From Jan:

    This is not a bug, you just can't use the same id twice because this generates invalid html. You could have a look at modules in order to avoid conflicting ids