How to update shiny controls in dynamic rmarkdown document?

584 views
Skip to first unread message

chris warth

unread,
Oct 13, 2014, 5:43:22 PM10/13/14
to shiny-...@googlegroups.com


Is there any way to update the contents of a selectInput control inside an rmarkdown document?
For example, in the document below I would like the selectInput for B to have different choices depending on the value chosen for A.

It almost looks like one could use updateSelectizeInput(), but that takes a 'session' argument which I don't see exposed in rmarkdown.

Any ideas?
---
title: "An Empty Document"
output: html_document
runtime: shiny
---
This space intentionally left blank.
```{r eval=TRUE, echo=FALSE}
inputPanel(
    selectInput("A", "Control A:",  choices = c("A", "B", "C")),
    selectInput("B", "Control B:",  choices = c("1", "2", "3")),
    selectInput("C", "Control C:",  choices = NULL)
)

```
```{r eval=TRUE, echo=FALSE}

reactive({
    if (input$A == "B") {
        # I would like to update the choices for selectInput B here.
    }
})
```

Vincent

unread,
Oct 14, 2014, 4:32:53 AM10/14/14
to shiny-...@googlegroups.com
I haven't used shiny in rmarkdown at all yet but ... can you use renderUI? In a regular Shiny app, within renderUI you can do a check for the value of input$A and then adjust the values available to B (which could be only one value).

Joe Cheng

unread,
Oct 14, 2014, 7:20:43 PM10/14/14
to Vincent, shiny-...@googlegroups.com
You can use updateSelectInput, the "session" is available implicitly. But you need to use observe, not reactive. So this:

reactive({
    if (input$A == "B") {
        # I would like to update the choices for selectInput B here.
    }
})

should be:

observe({

    if (input$A == "B") {
        updateSelectInput(session, "B", choices = ...)
    }
})

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/9fc2e682-2f9b-425e-a19e-bf6e05694425%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

chris warth

unread,
Oct 14, 2014, 7:35:29 PM10/14/14
to shiny-...@googlegroups.com
renderUI() did not seem to have any effect inside of an rmarkdown document, whereas it works fine for me inside of a traditional shiny app.

- Chris

Joe Cheng

unread,
Oct 15, 2014, 3:50:24 AM10/15/14
to chris warth, shiny-...@googlegroups.com
It should work--in fact the entire runtime:shiny mechanism is based on a big renderUI call. Any chance you can provide the code you tried?

On Tue, Oct 14, 2014 at 4:35 PM, chris warth <csw...@gmail.com> wrote:
renderUI() did not seem to have any effect inside of an rmarkdown document, whereas it works fine for me inside of a traditional shiny app.

- Chris

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages