library(shiny)
ui <- fluidPage( actionButton("btn", "Click"), uiOutput("out"))
server <- function(input, output) { values <- reactiveValues(foo = NULL) observeEvent(input$btn, { values$foo <- "bar" Sys.sleep(1)
})
output$out <- renderUI({ values$foo })}
shinyApp(ui = ui, server = server)
--
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/db6c0683-25fd-4818-8212-832db1d56f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
library(shiny)
ui <- fluidPage( actionButton("btn", "Click"), uiOutput("out"))
## A function that returns a reactiveVal that invalidates in the next flush AFTER expr_q has invalidatedflush_wait <- function(expr_q, env=parent.frame()) { transfer_reactive <- reactiveVal() # add transfer shiny::observeEvent(expr_q, { n_run <- 0 o <- observe({ invalidateLater(1) if (n_run==1) { transfer_reactive(runif(1)) } if (n_run > 1) { o$destroy() } n_run <<- n_run+1 }); },event.env=env,event.quoted=TRUE) return(transfer_reactive)}
server <- function(input, output,session) { values <- reactiveValues(foo = NULL) # return a reactiveVal that invalidates in the next flush AFTER values$foo has been assigned invalidate_after_assigned <- flush_wait( quote({ req(input$btn); values$foo <- paste0("Button click #",input$btn) }) ) observe({ req(invalidate_after_assigned()) Sys.sleep(1) showModal(modalDialog("Long observer finished running")) }) output$out <- renderUI({ values$foo })}
shinyApp(ui = ui, server = server)