Home > Mobile >  R Shiny navbarPage; values not loading from server
R Shiny navbarPage; values not loading from server

Time:08-29

Help! For the life of me, I can't get values to populate from the server to the infoBox in the UI. I've tried to define the infoboxes from the server section, but the infoboxes will only appear if I construct them in the UI (as shown below).

The goal is to populate the boxes with filtered data based on user inputs, but I've abandoned this at this stage because I can't even pass a value from the server to the UI infobox here:

infoBox("Participants Trained", 
       value = renderText("AYval"), # tried every combo here
       width = 12,color = "blue",  # tried width = NULL
       icon = icon("fa-solid fa-people-group"), fill = F)

A value shows when I hardcode a value in "value = ", but none of the render options, renderText, verbatimText, output$AYval, valueTextbox, listen(),react() will get a value that is hard-coded in the server side to show up in this infobox.

To get the dashboard to display boxes, I'm using header = tagList(useShinydashboard()). My guess is this useShinydashboard() is the culprit.

I thought this App looks like this

CodePudding user response:

Here's a small reproducible example of how to change the value contents dynamically:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)

data(iris)

ui <- navbarPage(
  fluid = TRUE,
  theme = shinythemes::shinytheme("flatly"),
  collapsible = TRUE,
  header = tagList(
    useShinydashboard()
  ),
  tabPanel("START"),
  tabPanel(
    title = "Home Dashboard",
    value = "Tab1",
    selectInput("column",
                label = "Select a column",
                choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
    ),
    box(
      width = 4,
      infoBoxOutput("test")
    )
  )
)

server <- function(input, output, session) {
  iris_sum <- reactive({
    sum(iris[input$column])
  })
  
  output$test <- shinydashboard::renderInfoBox({
    infoBox(
      title = "Where?",
      value = iris_sum(),
      width = 12,
      color = "blue",
      fill  = F
    )
  })
}

shinyApp(ui, server)

enter image description here

  • Related