I am attempting to upload my first post to a Hugo blog using RMarkdown. Below you can find my code creating the document:
---
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::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.
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.
Thank you!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With