Jor*_*rge 12 r r-markdown shiny blogdown
我正在尝试使用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))
)
```
Run Code Online (Sandbox Code Playgroud)
我将此保存为与blogdown目录相关的R项目的Posts部分中的.Rmd文件.当我跑:
blogdown::serve_site()
Run Code Online (Sandbox Code Playgroud)
我收到错误说:错误:未提供html_dependency的路径执行停止render_page(f)中的错误:上面显示的页面.
我是blogdown的新手,无法找到这个错误的解决方案,所以如果有人能提供一些解决方法来解决这个错误,并将交互式闪亮应用程序包含在Hugo中,请告诉我.
谢谢!
Yih*_*Xie 20
该blogdown包是静态网站,这意味着你只能生成静态页面.闪亮的应用程序依赖于实时R会话,因此除非您使用iframe,否则它们不能嵌入到静态HTML页面中.也就是说,你不能runtime: shiny在博客中使用Shiny R Markdown文档().您必须在可以使用R和Shiny Server的服务器上发布Shiny应用程序,并使用<iframe src="URL-OF-YOUR-SHINY-APP"></iframe>该应用程序在网页上嵌入应用程序.