11.2 Modifying app to be bookmarkable

There are three main parts you must modify in a Shiny app in order for it to be bookmarkable:

  1. In the ui: make it a function
  2. In the ui: add the bookmarkButton() function
  3. In the shinyApp() call: include enableBookmarking = "url"
ui <- function(request) {
  fluidPage(
    sidebarLayout(
      sidebarPanel(
        sliderInput("omega", "omega", value = 1, min = -2, max = 2, step = 0.01),
        sliderInput("delta", "delta", value = 1, min = 0, max = 2, step = 0.01),
        sliderInput("damping", "damping", value = 1, min = 0.9, max = 1, step = 0.001),
        numericInput("length", "length", value = 100),
        bookmarkButton()
      ),
      mainPanel(
        plotOutput("fig")
      )
    )
  )
}

shinyApp(ui, server, enableBookmarking = "url")

  1. Making the ui a function
    1. Why? Because Shiny needs to be able to modify the input controls specified by the URL. Like arguments are passed within a normal R function as parameters to produce different outputs, the ui now needs to take in an argument (the URL) in order to return the app into a particular state. The URL holds information on the input parameters that needs to be changed, hence why the ui now needs to be a function.
  2. Adding the bookmarkButton() button to the app
    1. This function adds a button to the ui that captures the current values of all the input controls and generates a URL from it. More on this later.
  3. Adding enableBookmarking = "url" to the shinyApp() call
    1. This function ultimately puts the app together - the ui and the server. Adding this argument tells Shiny enable bookmarking and that the bookmark will be URL-encoded vs saved-on-server. More on this later