flexdashboard和updateSelectInput - 不会为我的生活而工作

时间:2018-03-14 13:11:41

标签: shiny flexdashboard

尝试进行selectInput的选择范围取决于第一个selectInput的值。

Flexboard标题如下所示:

---
title: "blabla"
output:
   flexdashboard::flex_dashboard:
   orientation: rows
   social: menu
   source_code: embed
   theme: cerulean
runtime: shiny
---

以下代码编译但不起作用,位于.sidebar块中。我正在尝试使用输入$ book来交互式地改变" chapter"的范围。 selectInput。不幸的是,updateSelectInput()似乎什么都不做。

# Inputs {.sidebar data-width=150}

```{r}
selectInput("book", label = "libro", choices = c("dq1605", "dq1615"), selected="dq1605")
selectInput("chapter", label = "capítulo",choices = 0:54, selected=0)

observeEvent(input$book, {
   y <- input$book
   if (is.null(y)) y <- "dq1605"
   chs <- if(y=="dq1605") 0:54 else 0:74
   updateSelectInput(session,"chapter",choices = chs)
})
```

我投入了几个小时试图完成这项工作(我也使用了更简单的observeEvent({})),但无济于事。有什么建议吗?

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.3      backports_1.1.2     magrittr_1.5        rsconnect_0.8.5    
 [5] rprojroot_1.3-2     htmltools_0.3.6     tools_3.4.3         flexdashboard_0.5.1
 [9] yaml_2.1.16         Rcpp_0.12.15        stringi_1.1.6       rmarkdown_1.9      
[13] knitr_1.20          jsonlite_1.5        stringr_1.2.0       digest_0.6.15      
[17] evaluate_0.10.1

1 个答案:

答案 0 :(得分:1)

它实际上对我有用。 我改变的是选择= max(chs)&#39;让它更容易看出它是否有效。

无法看到您的任何套餐比我的旧。

---
title: "blabla"
output:
   flexdashboard::flex_dashboard:
   orientation: rows
   social: menu
   source_code: embed
   theme: cerulean
runtime: shiny
---

# Inputs {.sidebar data-width=150}

```{r}
selectInput("book", label = "libro", choices = c("dq1605", "dq1615"), selected="dq1605")
selectInput("chapter", label = "capítulo",choices = 0:54, selected=0)

observeEvent(input$book, {
   y <- input$book
   if (is.null(y)) y <- "dq1605"
   chs <- if(y=="dq1605") 0:54 else 0:74
   updateSelectInput(session, "chapter", choices = chs, selected = max(chs))
})
```