【问题标题】:Incorporating interactive shiny apps into Rmarkdown document for blogdown Hugo blog将交互式闪亮应用程序合并到用于 blogdown 的 Rmarkdown 文档中 Hugo blog
【发布时间】:2018-02-18 12:58:47
【问题描述】:

我正在尝试使用 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))
)
```

我将其保存为 .Rmd 文件,位于与 blogdown 目录相关的 R 项目的 Posts 部分中。当我跑步时:

blogdown::serve_site()

我收到一条错误消息: 错误:未提供 html_dependency 的路径 执行停止 render_page(f) 中的错误: 如上所示的页面。

我是 blogdown 的新手,无法找到解决此错误的方法,所以如果有人可以提供一些有关如何解决此错误并将交互式闪亮应用程序包含到 Hugo 中的见解,请告诉我。

谢谢!

【问题讨论】:

标签: r shiny r-markdown blogdown


【解决方案1】:

blogdown 包适用于静态网站,这意味着您只能生成静态页面。闪亮的应用程序依赖于实时 R 会话,因此除非您使用 iframe,否则它们不能嵌入到静态 HTML 页面中。也就是说,您不能将 Shiny R Markdown 文档 (runtime: shiny) 与 blogdown 一起使用。您必须在 R 和 Shiny Server 可用的服务器上发布 Shiny 应用,并使用 &lt;iframe src="URL-OF-YOUR-SHINY-APP"&gt;&lt;/iframe&gt; 将应用嵌入到网页中。

【讨论】:

  • 感谢您的澄清。
  • 易辉你在哪里安装iframe代码?谢谢。
  • @astronomerforfun 在 (R) Markdown 源文件中。
  • @YihuiXie 你有没有机会提供一个可靠的窗口调整代码?
猜你喜欢
  • 2020-10-21
  • 2017-12-22
  • 2016-02-03
  • 1970-01-01
  • 2016-03-25
  • 2017-09-16
  • 2016-01-11
  • 2021-10-11
  • 2014-08-09
相关资源
最近更新 更多