Page refresh Button in R shiny
12,439
Just to be complete, the code below is a minimal example of a working Shiny app that uses a "refresh" button
library(shiny)
library(shinyjs)
jscode <- "shinyjs.refresh = function() { history.go(0); }"
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = jscode),
textInput("text", "Text"),
actionButton("refresh", "Refresh app")
)
server <- function(input, output, session) {
observeEvent(input$refresh, {
js$refresh();
})
}
shinyApp(ui = ui, server = server)
Edit: Since shiny version 0.13.0, it's possible to refresh the page using Shiny's session$reload()
function
Author by
Rajarshi Bhadra
Updated on June 18, 2022Comments
-
Rajarshi Bhadra almost 2 years
I tried to implement a page refresh button following the link here. However when I tried deploying to
shinyapp.io
, it failed and asked for installing packageV8
which I had already done. The app was working fine on the machine. The code I used is:jsResetCode <- "shinyjs.reset = function() {history.go(0)}", useShinyjs(), # Include shinyjs in the UI extendShinyjs(text = jsResetCode), # Add the js code to the page p(actionButton("reset_button", "Reset Tool"))
In
server.R
:observeEvent(input$reset_button, {js$reset()})
Is there any way to do this without
shinyjs
? -
MMAASS about 5 yearsHi, thanks for your input, I had the same question and it worked very well by following your answer. I am wondering how would I implement your code to create page refresh buttons on multiple tabs. I posted my question here: stackoverflow.com/questions/55262781/…. I greatly appreciate your help!
-
dca about 3 yearsThe edit is helpful: just use session$reload()
-
Avery Robbins about 3 yearsYeah love the edit. I would put it at the top so its the first thing people see. I started installing shinyjs haha