Hi,
As far as my knowledge goes, I'm afraid this will not be possible without any hacks as Shiny always waits for a process to finish before updating the UI.
If you're looking for a simple progress message, that is possible through the Progress function
https://shiny.rstudio.com/reference/shiny/0.14/Progress.html
If you really want to update a UI element, you'll need custom JS as far as I can see. I've come up with one example:
library(shiny)
library(shinyjs)
ui <- fluidPage(useShinyjs(),
tags$script(HTML(
"
$(document).on('shiny:inputchanged', function(event) {
if (event.name === 'myButton') {
document.getElementById('myUI').innerHTML = '<h1>loading...</h1>';
}
});
"
)),
actionButton("myButton", "Click"),
uiOutput("myUI")
)
server <- function(input, output, session) {
theUI = reactiveVal(tags$h1("Initial state"))
observeEvent(input$myButton, {
Sys.sleep(3)
# theUI("Done") # wont work after first time
output$myUI = renderUI({
tags$h1("Done")
})
})
output$myUI = renderUI({
theUI()
})
}
shinyApp(ui, server)
I took advantage of the client side JS to update the UI element of interest when the button is clicked, regardless of how long the process takes.
Unfortunately, this does not update any reactive variables in Shiny. I found this out because I originally had the line theUI("Done") to update the UI once the code finished. This works the first time round, but because it's not updated to loading... as this is done client side, the value stays the same and the next time this won't trigger the output$myUI as Shiny does not execute reactive variables if they don't change value. I hoep this makes sense (just try it). I fixed that by calling the output$myUI directly in the code to force the update.
Hope this helps,
PJ