rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
887 stars 299 forks source link

output 5 values (Characters & Numbers at the same time) in Shinydashboard #276

Open JanaZraik opened 6 years ago

JanaZraik commented 6 years ago

I need to present top 5 customers depending on their Collective turnover.. in R Console, I get the 5 customers one after another in 5 rows.

But on the dashboard itself, I get only the first row: here is a screenshot of the Console: (i hided the names of the customers because this data is private) image

and this is the dashboard outcome: image as you can see, it gives only the 1st customer of the top five, and without presenting its turnover in numbers

any help please?

thank you very much

ismirsehregal commented 5 years ago

As far as I am concerned valueBoxes are intended to show single values (also see here). Accordingly you would need to pass each row to the valueBox function and display them separately. I’d rather go for a bar-chart.

library(shiny)
library(shinydashboard)
library(tibble)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(uiOutput("Boxes"))
)

server <- function(input, output) {
  custData <- tibble(Customer = paste0("Customer_", LETTERS[1:5]), Collective = round(runif(5, 10000, 20000)))

  boxesList <- list()
  for(i in seq(nrow(custData))){
    boxesList[[i]] <- valueBox(value = custData$Collective[i], subtitle = custData$Customer[i], icon = icon("industry"))
  }

  output$Boxes <- renderUI({boxesList})
}

shinyApp(ui, server)