ValueBox not correctly displayed

I'm trying to render a valueBox in a shiny app, but I get only the text.


column(6, valueBoxOutput("PercentageEnv1")),
column(6, valueBoxOutput("PercentageEnv2")))


output$PercentageEnv1 <- renderValueBox({

    valueBox(paste0(PercEnv1_a, "%"),
             subtitle = "non matching tables in Env 1",
             color = "teal")
  output$PercentageEnv2 <- renderValueBox({
    valueBox(paste0(PercEnv2_a, "%"),
             subtitle = "non matching tables in Env 2",
             color = "blue")

Any ideas of what is causing this behavior?

1 Like

Are PercEvn1_a and PercEnd2_a reactive values, or just constants defined somewhere else (I can't see how you make them)?

They are relative values, I calculate them every time as (Nr.mismatches/Total)*100.

The value showed is correct but I don't get the value box graphic part.

Reactive values (i.e. those created with reactive()) need to be called with () inside render functions, e.g.

  valueBox(paste0(PercEnd1_a(), "%"), ...

Do you need to do that? Or do you mean that the value boxes don't show up at all in the UI?

I tried with the parenthesis but it returns an error

Error in paste0: could not find function "PercEnv2_a"

I'm attaching an image of how it looks like: the problem is that there is no colored box, like it would expect.

Do you create PercEnv... values inside a reactive() call? (If you don't then they aren't reactive, and you don't need the brackets. The error message suggests they're not).

What version of R, Shiny and/or shinydashboard are you using? There are other arguments around colour, logos etc that you can pass to valueBox(), does using them change things?

Sorry but valueBoxOutput and the other features of shinydashboard, are only available when being used with a dashboardPage. The CSS is all defined at the page level. If you were sufficiently motivated, you could probably figure out the CSS styles you need and extract them from the shinydashboard package. (I'm guessing this, for a start?)


Ok, so that was the problem then. Can I get a navbar result with a dashboardPage or does one exclude the other?

shinydashboard has a very strict structure, unlike Shiny. However, you can still do a LOT with it. Instead of the tabs in navbarPage, you can use the sidebar to get a multi-page app. See this for examples and a walk-through.