0

I am trying to plot a gauge plot within ShinyDashBoard and I am seeing two issues.

1) The gauge plot does not render

2) It somehow corrupts the ValueBox in the dashboard.

Below is the code to replicate this issue.

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)

Also plots generated using plotly library :-( Any help on resolving this issue is much appreciated. Thanks in advance.

missy morrow
  • 337
  • 3
  • 16

3 Answers3

1

I ran into the same issue!

It's a UI thing -- look at your code when you call the server output. You'll want to use flexdashboard::gaugeOutput("plt1") instead of plotlyOutput. That should solve the problem.

Reference: https://cran.r-project.org/web/packages/flexdashboard/flexdashboard.pdf (i.e. just the flexdashboard package page).

Nemanja Trifunovic
  • 3,017
  • 1
  • 17
  • 20
0

You should use renderGauge instead of renderPlot. And gaugeOutput instead of plotOutput.

Ilona
  • 446
  • 4
  • 12
-1

1.In UI

column(6,box(gaugeOutput("plt1"),width=12,title="Gauge Graph",background ="green") )

In Server

output$plt1 <- renderGauge({
      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")
      ))
    })

2.

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