在编织闪亮的RMarkdown HTML文档时,我有一些非常奇怪的行为。在下面的MWE中,我简单地(1)包括一个滑动输入,(2)在df中包含一列作为输入的值,然后(3)返回df。下面的MWE返回错误Error in : Column "b" must be length 1 (the number of rows),not 0
。如果在将值赋给b时取出输入值的乘积,文档将毫无问题地进行编织。 MWE:
---
output: html_document
runtime: shiny
---
```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
```
Testing
```{r eruptions,echo=FALSE}
# Input slider
sliderInput("test","Test",value = 0.5,min = 0,max = 1,width = "100%")
# Pre-define df
output <- reactiveValues(data = data.frame(a = 20))
observe({
output$data <- output$data %>%
# Manipulate df
mutate(b = input$test * 2)
})
# Return df
renderDataTable({output$data})
```
有人知道是什么原因导致这种奇怪的行为吗?