I cannot get both the markdown document to knit to html and the shiny code to function simulaneously. Here is my code:
---
title: "Report"
author: "Name"
date: "`r Sys.Date()`"
output:
html_document:
df_print: paged
runtime: shiny
editor_options:
markdown:
wrap: 72
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(leaflet)
library(rgdal)
library(sf)
library(dplyr)
library(RColorBrewer)
library(htmlwidgets)
```
## Summary
Text
## Section
Text
```{r, echo = FALSE}
wave_data <- read_sf("~/path/Wave_data_32631.geojson")
wave_data <- st_transform(wave_data, crs = '+proj=longlat
+datum=WGS84')
wave_data2 <- wave_data %>%
mutate_at(vars(An_mn_P_OD), ~ as.integer(round(.x)))
bins <- c(0, 25, 50, 100, 150, 200, 300, 400, 500, 1000, 3100)
pal <- colorBin("RdYlBu", domain = wave_data2$Ave_Depth, bins = bins)
# Define UI for application
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body
{width:100%;height:100%}"),
leafletOutput("wave_data_map", width = "100%", height =
"100%"),
absolutePanel(top = 10, right = 10,
sliderInput("wave_data_range", "Wave energy",
min = 0, max = 75,
value = c(min(wave_data2$An_mn_P_OD),
max(wave_data2$An_mn_P_OD)),
step = 5,
round = 0.5,
dragRange = TRUE)
)
)
# Define server logic
server <- function(input, output, session) {
wave_energy_output <- reactive({
data <- wave_data2 %>%
filter(An_mn_P_OD >= input$wave_data_range[1],
An_mn_P_OD <= input$wave_data_range[2])
data %>% group_by(Lat)
})
output$wave_data_map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$Esri.WorldTopoMap) %>%
setView(lng = -4.2026458, lat = 56.4906712, zoom = 5) %>%
addPolygons(data = wave_data2,
weight = 1,
smoothFactor = 0.5,
color = "white",
fillOpacity = 0.3,
fillColor = pal(wave_data2$Ave_Depth)) %>%
addLegend(pal = pal,
values = wave_data2$Ave_Depth,
title = "Average depth",
labFormat = labelFormat (suffix = "m"),
opacity = 0.7,
position = "bottomright")
})
observeEvent(input$wave_data_range, {
data <- wave_energy_output()
leafletProxy("wave_data_map", data = data) %>%
clearShapes() %>%
addPolygons(data = data,
fillColor = pal(wave_energy_output()$Ave_Depth),
weight = 1,
smoothFactor = 0.5,
color = "white",
fillOpacity = 0.5)
})
}
# Run the application
shinyApp(ui = ui, server = server)
```
## Section
## Section
I have tried several iterations, it seems if I can get the shiny app to work the document will not knit to html, if I can knit to html, the shiny app doesn't work.
Please see earlier question if full capabiities necessary: R Shiny/R Leaflet/ R : Dynamically render choropleth map with sliderInput in R shiny 2
Any help always very much appreciated.