简体   繁体   中英

Display multiple infoboxes within one reactive function in R shiny

I wish to know if it is possible to create multiple infoBoxes with only one reactive function "ibox" as in the script below. I shall pass the values for all the infoboxes below within the ibox reactive function and see all of them getting displayed together.

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic boxes"),
dashboardSidebar(),
dashboardBody(
  fluidRow(
  infoBoxOutput("ibox")
  )))
server <- function(input, output) {
output$ibox <- renderInfoBox({
  infoBox(
    "Title",
    5,
    icon = icon("credit-card")
  )
  infoBox(
    "Title",
    5,
    icon = icon("credit-card")
  )
  infoBox(
    "Title",
    4,
    icon = icon("credit-card")
  )

  })}
  shinyApp(ui, server)

As mentioned in the comments, you could use renderUI and uiOutput . However, note that renderUI only actually renders the last statement in its body. In order to render multiple objects, we can place them in a list (or column , fluidRow , etc.). Working example:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(title = "Dynamic boxes"),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      uiOutput("ibox")
    )))
server <- function(input, output) {
  output$ibox <- renderUI({
    list(
      infoBox(
        "Title",
        5,
        icon = icon("credit-card")
      ),
      infoBox(
        "Title",
        5,
        icon = icon("credit-card")
      ),
      infoBox(
        "Title",
        4,
        icon = icon("credit-card")
      )
    )
  })}
shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM