将交互式闪亮应用程序合并到博客下载Hugo博客的Rmarkdown文档中

[英]Incorporating interactive shiny apps into Rmarkdown document for blogdown Hugo blog


I am attempting to upload my first post to a Hugo blog using RMarkdown. Below you can find my code creating the document:

我试图使用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))
)
```

I save this as an .Rmd file within the Posts section of the R project related to the blogdown directory. When I run:

我将此保存为与blogdown目录相关的R项目的Posts部分中的.Rmd文件。当我跑:

blogdown::serve_site()

I get an error saying: Error: path for html_dependency not provided Execution halted Error in render_page(f): The page shown above.

我收到错误说:错误:未提供html_dependency的路径执行暂停render_page(f)中的错误:上面显示的页面。

I am new to blogdown and cannot find a solution to this error, so if anyone could provide some insight into how to work around this error and include interactive shiny apps into Hugo please let me know.

我是blogdown的新手,无法找到这个错误的解决方案,所以如果有人能够提供一些解决方法来解决这个错误,并在Hugo中包含交互式闪亮应用程序,请告诉我。

Thank you!

谢谢!

1 个解决方案

#1


16  

The blogdown package is for static websites, which means you can only generate static pages. Shiny apps depend on live R sessions, so they cannot be embedded on static HTML pages unless you use iframes. That is, you cannot use Shiny R Markdown documents (runtime: shiny) with blogdown. You have to publish the Shiny app on a server where R and Shiny Server are available, and use <iframe src="URL-OF-YOUR-SHINY-APP"></iframe> to embed the app on a web page.

blogdown包适用于静态网站,这意味着您只能生成静态页面。闪亮的应用程序依赖于实时R会话,因此除非您使用iframe,否则它们不能嵌入静态HTML页面。也就是说,你不能在博客中使用Shiny R Markdown文档(运行时:闪亮)。您必须在可以使用R和Shiny Server的服务器上发布Shiny应用程序,并使用


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2017/09/10/82f7ef5248c1c73769e5dc5ecedcc58b.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号