r googleVis 和 Shiny 嵌入在 r Markdown 中不呈现
r googleVis and Shiny embedded in r Markdown not rendering
我想 1) 在 shiney
中实现 r googleVis
图表和 2) 用 r Markdown
发布它。第一部分成功完成,请参阅我的代码的简单版本:
library(googleVis)
library(shiny)
shinyApp(
ui <- fluidPage(
h3('Example for the Whosebug 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 Whosebug 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 Whosebug 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'} },
}"))
})
}
)
```
结果输出如下所示:
为什么闪亮的应用程序没有呈现?
googlevis
需要到 Google 的 SSL 连接才能工作。因此它在 Rstudio 预览浏览器中不起作用,因为它似乎不支持 SSL 连接,当您尝试时,您会在 javascript 调试控制台中收到此错误:
(为了搜索引擎和阅读应用程序,错误消息是 "Failed to load resource: Unable to init SSL Context: https://www.google.com/...")
当我对 Shiny 和 Rmarkdown 使用 Rstudio 预览时,我得到了这个,所以我很惊讶你说它适用于 Shiny。也许你是 运行 在浏览器中?
可能有办法让 Rstudio 预览版浏览器执行 SSL,但对此表示怀疑。我认为这是有意为之的行为,因为 SSL 加密是 Rstudio Server Pro 的一项功能。
我在浏览器中运行良好(在预览 window 中单击 "Open in Browser"):
我想 1) 在 shiney
中实现 r googleVis
图表和 2) 用 r Markdown
发布它。第一部分成功完成,请参阅我的代码的简单版本:
library(googleVis)
library(shiny)
shinyApp(
ui <- fluidPage(
h3('Example for the Whosebug 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 Whosebug 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 Whosebug 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'} },
}"))
})
}
)
```
结果输出如下所示:
为什么闪亮的应用程序没有呈现?
googlevis
需要到 Google 的 SSL 连接才能工作。因此它在 Rstudio 预览浏览器中不起作用,因为它似乎不支持 SSL 连接,当您尝试时,您会在 javascript 调试控制台中收到此错误:
(为了搜索引擎和阅读应用程序,错误消息是 "Failed to load resource: Unable to init SSL Context: https://www.google.com/...")
当我对 Shiny 和 Rmarkdown 使用 Rstudio 预览时,我得到了这个,所以我很惊讶你说它适用于 Shiny。也许你是 运行 在浏览器中?
可能有办法让 Rstudio 预览版浏览器执行 SSL,但对此表示怀疑。我认为这是有意为之的行为,因为 SSL 加密是 Rstudio Server Pro 的一项功能。
我在浏览器中运行良好(在预览 window 中单击 "Open in Browser"):