我想1)在googleVis
中实施r shiney
图表,2)用r Markdown
发布它。第一部分成功完成,请参阅我的代码的简单版本:
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'} },
}"))
})
}
)
之后,我只是将我的代码复制并粘贴到RMarkdown模板中:
---
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'} },
}"))
})
}
)
```
为什么闪亮的应用程序不呈现?
答案 0 :(得分:2)
googlevis
需要与Google建立SSL连接才能正常运行。所以它在Rstudio预览浏览器中不起作用,因为它似乎不支持SSL连接,当您尝试时,在javascript调试控制台中出现此错误:
(为了搜索引擎和阅读应用程序,错误消息是&#34;无法加载资源:无法初始化SSL上下文:https://www.google.com/ ...&#34;)
当我对Shiny和Rmarkdown使用Rstudio预览时,我得到了这个,所以我很惊讶你说它适用于Shiny。也许你是在浏览器中运行它?
可能有办法让Rstudio预览浏览器执行SSL,但是对此表示怀疑。我认为这是故意行为,因为SSL加密是Rstudio Server Pro功能。
虽然它在浏览器中对我有用(点击&#34;在浏览器中打开&#34;在预览窗口中):