r - Using renderLeaflet() inside an interactive document (Rmarkdown)
问题描述
I'm trying to create an interactive document like the tutorial on Shiny's website. However, I want the plot to be a Leaflet map. Following the Leaflet tutorial, it seems like the following should work using leaflet::renderLeaflet()
instead of shiny::renderPlot()
.
Instead, I get an error when running the document: Error: object 'input' not found
. Is there a special way to expose input
to leaflet when using Shiny widgets inside an interactive Rmarkdown document?
---
runtime: shiny
output: html_document
---
```{r echo = FALSE}
library(magrittr)
shiny::selectInput(
"weight", label = "Weight:",
choices = c(1, 2, 3, 4, 5), selected = 5
)
```
```{r include = FALSE}
csa <- tigris::combined_statistical_areas(class = "sf")
```
```{r echo = FALSE}
leaflet::renderLeaflet({ # <- main difference from tutorial
leaflet::leaflet() %>%
leaflet::addTiles() %>%
leaflet::addPolylines(data = csa, color = '#333', weight = input$weight)
})
```
解决方案
推荐阅读
- c# - ASP.Net 网站和多目标框架 - 依赖错误
- gradle - Grails - IntelliJ 无法解析符号和对象
- php - 数据库正确注册用户,但没有发送电子邮件
- perl - perl 中的 Given-when-continue 语句
- python - 如何使用正则表达式(Python)将更正插入文件
- tensorflow - 如何将 TensorFlow 数据集列合并到 Keras 的(特征、标签)元组中?
- c - 带有参数的缓存 numba jited 函数包括函数对象
- apache-spark - Spark Streaming:长时间运行后许多排队的批次没有问题
- python - 如果列包含在另一个数据框中指定的字符串,则从数据框中的列中获取平均值
- python - 如何在 TensorFlow 中直接向我的输入层添加偏差和激活函数?