Restart Shiny Session

You can use the history.go(0) js-method to reload the page and thus reset the session, e.g. from a link:

p(HTML("<A HREF=\"javascript:history.go(0)\">Reset this page</A>"))

Furthermore you can use the shinyjs package to execute javascript from within the server:

library(shiny)
library(shinyjs)

jsResetCode <- "shinyjs.reset = function() {history.go(0)}" # Define the js method that resets the page

shinyApp(
  ui = fluidPage(
    useShinyjs(),                                           # Include shinyjs in the UI
    extendShinyjs(text = jsResetCode, functions = "reset"), # Add the js code to the page
    actionButton("reset_button", "Reset Page")
  ),

  server = function(input, output) {
    observeEvent(input$reset_button, {js$reset()})          # Call the method from
                                                            # somewhere within the server
  })

The session has now a method to do the trick. Shinyjs is no longer required:

session$reload()

You can add a refresh icon and popover to your app by including the following in your ui code:

library(shinyBS)

tags$a(href="javascript:history.go(0)", 
           popify(tags$i(class="fa fa-refresh fa-5x"),
                  title = "Reload", 
                  content = "Click here to restart the Shiny session",
                  placement = "right"))

It should give you this:

enter image description here

Tags:

R

Shiny

Shinyjs