简体   繁体   中英

R Shiny valueBox and gauge not working together

I'm having an issue with my Shiny App. My app has a valueBox that worked fine before I introduced a gauge from the flexdashboard package.

With the gauge my valueBox not longer renders in the UI.

Reading other posts, I think this is an issue with the flexdashboard package.

Any work arounds would be much appreciated.

Some reproducible code below:

library(shiny)
library(shinydashboard)
#library(flexdashboard)


ui <-dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
  valueBoxOutput("vbox1"),
  column(6,box(plotOutput("plt1"),width=12,title="Gauge Graph",background ="green") ),

column(6,box(plotOutput("plt2"),width=12,title="Graph2",background="yellow") )
),
fluidRow( actionButton("plot","plot") )
)
)

server <- shinyServer(function(input, output, session) {
observeEvent(input$plot,{
output$plt1 <- renderPlot({
  flexdashboard::gauge(56, min = 0, max = 100, symbol = '%', label = paste("Test Label"),gaugeSectors(
    success = c(100, 6), warning = c(5,1), danger = c(0, 1), colors = c("#CC6699")
  ))

})
output$plt2 <- renderPlot({plot(runif(100),runif(100))})
})

output$vbox1 <- renderValueBox({
valueBox(
  "Gender",
  input$count,
  icon = icon("users")
 )
})
})

shinyApp(ui = ui, server = server)

You could use flexdashboard namespace instead of sourcing the library.

You could do something like this:

library(shiny)
library(shinydashboard)
# library(flexdashboard)


ui <-dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      valueBoxOutput("vbox1"),
      column(6,box(flexdashboard::gaugeOutput("plt1"),width=12,title="Gauge Graph",background ="green") ),

      column(6,box(plotOutput("plt2"),width=12,title="Graph2",background="yellow") )
    ),
    fluidRow( actionButton("plot","plot") )
  )
)

server <- shinyServer(function(input, output, session) {
  observeEvent(input$plot,{
    output$plt1 <- flexdashboard::renderGauge({
      flexdashboard::gauge(56, min = 0, max = 100, symbol = '%', label = paste("Test Label"),
                           flexdashboard::gaugeSectors(success = c(100, 6), warning = c(5,1), danger = c(0, 1), colors = c("#CC6699")
      ))

    })
    output$plt2 <- renderPlot({plot(runif(100),runif(100))})
  })

  output$vbox1 <- renderValueBox({
    valueBox(
      "Gender",
      input$count,
      icon = icon("users")
    )
  })
})

shinyApp(ui = ui, server = server) 

Using this code the app looks like this: 在此处输入图片说明

Hope it helps!

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