我正在尝试使用RMarkdown将我的第一篇文章上传到Hugo博客。您可以在下面找到我创建文档的代码:
---
title: "Untitled"
author: "Jorge"
date: "September 9, 2017"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r echo=FALSE, include=FALSE}
data('USArrests')
head(USArrests)
```
```{r echo = TRUE, include = FALSE}
library(tidyverse)
library(maps)
library(mapproj)
library(geosphere)
library(ggrepel)
library(scales)
library(RColorBrewer)
library(plotly)
library(shiny)
```
## Map
```{r, echo = FALSE, include = TRUE}
us_states <- map_data('state')
USArrests$region <- tolower(row.names(USArrests))
arrest_map_data <- merge(us_states, USArrests, by = 'region')
arrest_map_data <- arrest_map_data[order(arrest_map_data$order),]
inputPanel(
selectInput("crime", label = "Crime: ",
choices = list('Murder' = 'Murder',
'Assault' = 'Assault',
'Rape' = 'Rape'), selected = 'Murder')
)
renderPlot(
ggplot() + coord_map() +
geom_map(data = arrest_map_data, map = arrest_map_data,
aes(x = long, y = lat, map_id = region),
fill = "grey80", color = "black", size = 0.15) +
geom_polygon(data = arrest_map_data, aes_string(x = 'long', y = 'lat',
group = 'group', fill = input$crime)) +
scale_fill_gradient(low = 'light blue', high = 'dark blue', name = 'Arrests per 100,000\nresidents') +
theme(legend.position = 'bottom',
panel.grid = element_blank(),
panel.background = element_blank(),
axis.text = element_blank(),
axis.title = element_blank())
)
```
## Scatterplot
```{r, echo = FALSE, include = TRUE}
inputPanel(
checkboxGroupInput("crime2", label = "Crime: ",
choices = list('Murder' = 'Murder',
'Assault' = 'Assault',
'Rape' = 'Rape'), selected = c('Murder', 'Assault'))
)
renderPlotly(
ggplotly(ggplot(data = USArrests,
aes_string(x = input$crime2[1], y = input$crime2[2], text = input$region)) +
geom_point(fill = "grey80", color = "black", size = (USArrests$UrbanPop) / 10))
)
```
我将此保存为与博客目录相关的R项目的帖子部分中的.Rmd文件。我跑的时候:
blogdown::serve_site()
我收到一条错误消息: 错误:未提供html_dependency的路径 执行停止 render_page(f)出错: 上面显示的页面。
我是blogdown的新手,无法找到此错误的解决方案,因此,如果有人能够提供一些有关如何解决此错误的信息,并在Hugo中包含交互式闪亮应用,请告诉我们。
谢谢!
答案 0 :(得分:18)
blogdown 包适用于静态网站,这意味着您只能生成静态网页。闪亮的应用程序依赖于实时R会话,因此除非您使用iframe,否则它们不能嵌入到静态HTML页面中。也就是说,您不能将Shiny R Markdown文档(runtime: shiny
)与 blogdown 一起使用。您必须在可以使用R和Shiny Server的服务器上发布Shiny应用程序,并使用<iframe src="URL-OF-YOUR-SHINY-APP"></iframe>
将应用程序嵌入到网页中。