cnblevins
cnblevins

Reputation: 155

gvisGauge not displaying in R Shiny (empty space) - googleVis - Gauge

I am trying to display a simple Gauge using the googleVis library in R Shiny.

However - the only thing that I can get to display is a blank space that matches with the width and height of the INVISIBLE gauge. (I am having a similar image where I can't even get images to display using renderImage. So, the two fails may be connected.)

Any thoughts on how to fix the code below will be greatly appreciated:

From server.R:

output$gauge <- renderGvis({
M0 <- matrix(c('Label','Value'),ncol=2,byrow=TRUE)
M1 <- matrix(c('IRR',4),ncol=2,byrow=TRUE)
MU <- rbind(M0,M1)
df <- as.data.frame(MU)
gvisGauge(df,
options=list(min=0, max=10, greenFrom=8,
greenTo=10, yellowFrom=6, yellowTo=8,
redFrom=0, redTo=6, width=300, height=300));
})

From ui.R:

uiOutput("gauge")

Thanks,

Chad

Upvotes: 3

Views: 1475

Answers (1)

jdharrison
jdharrison

Reputation: 30425

Your data.frame was incorrectly specified

> M0 <- matrix(c('Label','Value'),ncol=2,byrow=TRUE)
> M1 <- matrix(c('IRR',4),ncol=2,byrow=TRUE)
> MU <- rbind(M0,M1)
> df <- as.data.frame(MU)
> df
     V1    V2
1 Label Value
2   IRR     4


library(shiny)
library(googleVis)
runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Number of obs', 4, 1, 10),
    htmlOutput("view")
  ),
  server = function(input, output) {
    output$view <- renderGvis({
     df <- data.frame(Label = "IRR", Value = input$n)
      gvisGauge(df,
                options=list(min=0, max=10, greenFrom=8,
                             greenTo=10, yellowFrom=6, yellowTo=8,
                             redFrom=0, redTo=6, width=300, height=300));

    })
  }
))

enter image description here

Upvotes: 3

Related Questions