11.8 Storing a richer state

URL bookmarking is simple and works everywhere you may want to deploy. Your Shiny app however, could become very long if you have a large number of inputs. If this is the case, it may be better to store your state on the server side.

Shiny saves the state of your app in an .rds file on the server and generates a shorter and easier URL. To do this, you can simply change the enableBookmarking argument to be “server” instead of “url”

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

This generates URLs like this: http://127.0.0.1:4087/?_state_id_=0d645f1b28f05c97

The parameter in this instance is the state_id which corresponds to a directory in your working directory - shiny_bookmarks/0d645f1b28f05c97

Caution: memory ⚠️ Be sure to have a mechanism to routinely delete these directories. If your app requires bookmarking in a complex state and you do not delete these files, your app is going to take up more disk space and may start to lag. However, when you do delete these files, their corresponding URLs will also stop working. Just be sure to either send updated links to stakeholders or be mindful of the state of your app.