JerryTheForester
JerryTheForester

Reputation: 476

r googleVis and Shiny embedded in r Markdown not rendering

I would like to 1) implement r googleVis chart in shiney and 2) publish it with r Markdown. The first part was done successfully, see the simple version of my code:

library(googleVis)
library(shiny)

shinyApp(
  ui <- fluidPage(
    h3('Example for the Stackoverflow Community'),
    htmlOutput('plot')
  ),

  server <- function(input, output) {
    output$plot <- renderGvis({

      DataF <- data.frame(From=c('A', 'B', 'C'),
                                 To=c('D','D', 'E'),
                                 Ponder=c(1, 2, 1.5))

      Sankey = gvisSankey(DataF,from="From", to="To", weight="Ponder",
                          options=list(width = "1200",
                                       height = "600",
                                       sankey="{
                                     link: {colorMode: 'gradient', color: { fill: '#green' } },
                                     node: {label: { color: 'black'},nodePadding: 80, width:50, color: { fill: '#a61d4c'} },
                                     }"))
    })
  }
)

After, I simply copied and pasted my code into RMarkdown template:

---
title: "Example for the Stackoverflow Community"
author: "JerryTheForester"
date: "12 januar 2017"
output: html_document
runtime: shiny
---

```{r echo=F}
library(googleVis)
library(shiny)

shinyApp(
  ui <- fluidPage(
    h3('Example for the Stackoverflow Community'),
    htmlOutput('plot')
  ),

  server <- function(input, output) {
    output$plot <- renderGvis({

      DataF <- data.frame(From=c('A', 'B', 'C'),
                                 To=c('D','D', 'E'),
                                 Ponder=c(1, 2, 1.5))

      Sankey = gvisSankey(DataF,from="From", to="To", weight="Ponder",
                          options=list(width = "1200",
                                       height = "600",
                                       sankey="{
                                     link: {colorMode: 'gradient', color: { fill: '#green' } },
                                     node: {label: { color: 'black'},nodePadding: 80, width:50, color: { fill: '#a61d4c'} },
                                     }"))
    })
  }
)
```

The resulted output is shown here: enter image description here

Why shiny application is not rendering?

Upvotes: 1

Views: 641

Answers (1)

Mike Wise
Mike Wise

Reputation: 22817

googlevis needs an SSL connection to Google to work. So it will not work in the Rstudio preview browser as that seems not to support SSL connections, you get this error in the javascript debugging console when you try: enter image description here

(for the sake of search engines and reading apps the error message is "Failed to load resource: Unable to init SSL Context: https://www.google.com/...")

I get this when I use the Rstudio preview for both Shiny and Rmarkdown, so I am surprised you said it worked for Shiny. Maybe you were running that in a browser?

There may be a way to get the Rstudio preview browser to do SSL, but doubt it. I think this is intentional behavior as SSL encryption is an Rstudio Server Pro feature.

It worked fine for me in the browser though (click on "Open in Browser" in your preview window):

enter image description here

Upvotes: 2

Related Questions