Reactive R/Shiny 示例在参数化一个变量后失败
Reactive R/Shiny Example Fails after Parameterizing One Variable
我有以下简单且有效的 shiny-Rmarkdown 文档。它产生一个滑块并在下面输出一个日期,该日期根据滑块输入进行调整。
---
runtime: shiny
output: html_document
---
```{r}
library(rmarkdown); library(ggvis); library(shiny);
sliderInput("sliderDays", "Days forward from 1/1/2014: ", min=0, max=45, value=1, step=1)
graphDate = reactive({as.Date("2014-01-01") + input$sliderDays})
renderPrint(graphDate())
```
但是,如果我将 graphDate = reactive({as.Date("2014-01-01") + input$sliderDays})
替换为
startDate <- as.Date("2014-04-01")
graphDate <- reactive({startDate + input$SliderDays})
然后 renderPrint(graphDate())
的输出来自
1 "2014-04-01" [this changes on slider input, but is always a date]
到
character(0)
我不明白为什么必须在 graphDate 反应函数中创建和使用 startDate,而不是在其上方定义并在反应函数中引用,这样才能起作用。
sessionInfo()
## R version 3.2.0 (2015-04-16)
## Platform: i386-w64-mingw32/i386 (32-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] DT_0.0.52 shiny_0.12.0 knitr_1.10.5 ggvis_0.4.1.9000
## [5] rmarkdown_0.6.2.2
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.11.6 digest_0.6.8 dplyr_0.4.1 assertthat_0.1
## [5] mime_0.3 R6_2.0.1 xtable_1.7-4 jsonlite_0.9.16
## [9] DBI_0.3.1 formatR_1.2 magrittr_1.5 evaluate_0.7
## [13] stringi_0.4-1 rstudioapi_0.3.1 tools_3.2.0 stringr_1.0.0
## [17] htmlwidgets_0.4 yaml_2.1.13 httpuv_1.3.2 parallel_3.2.0
## [21] htmltools_0.2.6
似乎对我有用。我没看错问题吗?
版本信息和会话信息:
我有以下简单且有效的 shiny-Rmarkdown 文档。它产生一个滑块并在下面输出一个日期,该日期根据滑块输入进行调整。
---
runtime: shiny
output: html_document
---
```{r}
library(rmarkdown); library(ggvis); library(shiny);
sliderInput("sliderDays", "Days forward from 1/1/2014: ", min=0, max=45, value=1, step=1)
graphDate = reactive({as.Date("2014-01-01") + input$sliderDays})
renderPrint(graphDate())
```
但是,如果我将 graphDate = reactive({as.Date("2014-01-01") + input$sliderDays})
替换为
startDate <- as.Date("2014-04-01")
graphDate <- reactive({startDate + input$SliderDays})
然后 renderPrint(graphDate())
的输出来自
1 "2014-04-01" [this changes on slider input, but is always a date]
到
character(0)
我不明白为什么必须在 graphDate 反应函数中创建和使用 startDate,而不是在其上方定义并在反应函数中引用,这样才能起作用。
sessionInfo()
## R version 3.2.0 (2015-04-16)
## Platform: i386-w64-mingw32/i386 (32-bit)
## Running under: Windows 7 x64 (build 7601) Service Pack 1
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] DT_0.0.52 shiny_0.12.0 knitr_1.10.5 ggvis_0.4.1.9000
## [5] rmarkdown_0.6.2.2
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.11.6 digest_0.6.8 dplyr_0.4.1 assertthat_0.1
## [5] mime_0.3 R6_2.0.1 xtable_1.7-4 jsonlite_0.9.16
## [9] DBI_0.3.1 formatR_1.2 magrittr_1.5 evaluate_0.7
## [13] stringi_0.4-1 rstudioapi_0.3.1 tools_3.2.0 stringr_1.0.0
## [17] htmlwidgets_0.4 yaml_2.1.13 httpuv_1.3.2 parallel_3.2.0
## [21] htmltools_0.2.6
似乎对我有用。我没看错问题吗?
版本信息和会话信息: