RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
455 stars 77 forks source link

DescriptionBlock - number_icon #14

Closed pro100mir closed 6 years ago

pro100mir commented 6 years ago

Hi, For "DescriptionBlock" - "number_icon" and "color" - how can they change the value based on the output of a function from server? I assume that if you are able to run the function "DescriptionBlock" in server, you can do this, but not sure how.

Thank you, Mircea

DivadNojnarg commented 6 years ago

Hi, like that for instance:

library(shiny)
library(shinydashboard)
shinyApp(
  ui = dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      fluidRow(
        box(
          solidHeader = FALSE,
          title = "Status summary",
          background = NULL,
          width = 4,
          status = "danger",
          footer = fluidRow(
            column(
              width = 6,
              uiOutput("descr1")
            ),
            column(
              width = 6,
              uiOutput("descr2")
            )
          )
        )
      ),
      fluidRow(
        column(
          width = 6,
          selectInput(
            "color", 
            "Block color:",
            choices = c("green", "orange", "maroon", "purple", "navy")
          )

        ),
        column(
          width = 6,
          selectInput(
            "icon", 
            "Icon:",
            choices = c("500px", "battery-1", "gg-circle", "industry", "map-pin")
          )
        )
      )
    ),
    title = "Description Blocks"
  ),
  server = function(input, output) {
    output$descr1 <- renderUI({
      descriptionBlock(
        number = "10%", 
        number_color = input$color, 
        number_icon = paste0("fa fa-", input$icon),
        header = "$35,210.43", 
        text = "TOTAL REVENUE", 
        right_border = TRUE,
        margin_bottom = FALSE
      )
    })

    output$descr2 <- renderUI({
      descriptionBlock(
        number = "20%", 
        number_color = input$color, 
        number_icon = paste0("fa fa-", input$icon),
        header = "1200", 
        text = "GOAL COMPLETION", 
        right_border = FALSE,
        margin_bottom = FALSE
      )
    })

  }
)

I use renderUI to programmatically handle these items.