Sleep Shiny WebApp to let it refresh... Any alternative?

231 views Asked by At

I have a WebApp that have some renderUI({})... and some of them depend on the input of another.

This makes that, briefly, a red error in the webpage appear when I select some options. Because the if() clause of some renderUI({}) depend on the input of a selectizer. The error says something like "The length of the argument is 0" (As the if() depends on a TRUE/FALSE, but in that exact moment it is not TRUE nor FALSE). After a second or so, it works good.

This could be done via a Sys.sleep() after the first if() but I don't know if it's the best option.

Thank you.

Edit - Reproducible code:

ui.R

radioButtons(
    inputId="select",
    label="Some selectizer",
    choices=list(
      "Yes",
      "No"
    ),
    selected="No",
    inline=TRUE
),

uiOutput("select1"),
uiOutput("option2")

server.R

output$select1 <- renderUI({
if (input$select == "No")
  return()

else radioButtons(
  inputId="select1",
  label="Some additional selector",
  choices=list(
    "Yes",
    "No"
  ),
  selected="No",
  inline=TRUE)
})

output$option2 <- renderUI({
  if (input$select == "Yes"){
    if (input$select1 == "Yes"){
      textInput("option2", "Some textInput: "), 
    }
    else return()
  }
})
1

There are 1 answers

3
hedgedandlevered On BEST ANSWER

some reproducible code would allow me to give you some example code, but in the absence of that...

wrap what you currently have in another if(), checking for length = 0 (or just && it, with the NULL check first), and display your favorite placeholder message.