Use query string variable to disable shiny widget on page load?

rmarkdown

#1

Here’s what I’d like to do in an Rmarkdown document with runtime: shiny -

  • Read the query string
  • Get a default argument for a textInput from variable in query string
  • Disable the textInput if variable in query string indicates

The problem seems to be that reading the query string must be done in a reactive context, but building the interface happens outside a reactive context. This is my first attempt, as an Rmarkdown file:

---
title: "Test session variables"
output: 
  flexdashboard::flex_dashboard:
    orientation: row
runtime: shiny
---

```{r}
require(flexdashboard)
require(shinyjs)
useShinyjs(rmd=TRUE)
```

```{r}

observe({
  query = getQueryString()
  ID = query[['ID']]
  active = query[['IDactive']]
  
  if (!is.null(ID)) {
    updateTextInput(session, 'ID', value = ID)
  }
  if(!is.null(active)){
    if(active == '0'){
      disable('ID')
    }
  }
})

```

Column {.sidebar}
-----------------------------------------------------------------------

```{r}
textInput("ID", label = "ID:", width = "150px", placeholder = "ID", value = "hi")
```

Row  {data-height=60}
------------------------------------

### Other 

Row 
-------------------------------------
    
### Query string

```{r}
renderUI({
    query <- getQueryString()
    return(HTML(jsonlite::toJSON(query)))
})
```

When I run this and add the appropriate variables in the query string, the textInput gets updated, but not disabled. Dean Attali (the author of shinyjs) has told me this is due to the fact that the textInput does not exist yet when the disable is run.

My question is: how can I use a variable in the query string to disable a widget when the Rmarkdown page loads?