Title: | Secure in-Browser Storage for 'Shiny' Inputs, Outputs and Variables |
---|---|
Description: | Store persistent and synchronized data from 'Shiny' inputs within the browser in a secure format. Refresh 'Shiny' applications and preserve user-inputs over multiple sessions. A database-like storage format is implemented using 'Dexie.js' <https://dexie.org>, a minimal wrapper for 'IndexedDB'. Transfer browser link parameters to 'Shiny' input or output values. |
Authors: | Obinna Obianom [aut, cre] |
Maintainer: | Obinna Obianom <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2 |
Built: | 2024-11-15 05:37:23 UTC |
Source: | https://github.com/oobianom/shinystoreplus |
Remove all stored inputs of an application
clearStore(appId, session = getDefaultReactiveDomain())
clearStore(appId, session = getDefaultReactiveDomain())
appId |
the application identification |
session |
session object |
No return value, called for side effects
Ensure not to use this function when the inputs are intended to be tracked.
if (interactive()) { library(shiny) library(shinyStorePlus) ui <- fluidPage( # initialize stores initStore(), "Sample delete storage", selectInput("dataset", label = "Dataset", choices = c("dataset 1", "dataset 2") ) ) server <- function(input, output, session) { appid <- "application01" clearStore(appId = appid) } shinyApp(ui, server) }
if (interactive()) { library(shiny) library(shinyStorePlus) ui <- fluidPage( # initialize stores initStore(), "Sample delete storage", selectInput("dataset", label = "Dataset", choices = c("dataset 1", "dataset 2") ) ) server <- function(input, output, session) { appid <- "application01" clearStore(appId = appid) } shinyApp(ui, server) }
Include Dexie and the package script in the header
initStore()
initStore()
Initialize the storage by including scripts necessary for the persistent storage handling
library(shiny) library(shinyStorePlus) if (interactive()) { ui <- shiny::fluidPage( # initialize stores initStore(), titlePanel("Sample shinyStorePlus Init Inputs"), sidebarLayout( sidebarPanel( sliderInput("nextgenshinyapps1", "Number of bins:", min = 1, max = 200, value = 150 ), textInput( "caption", "simple caption:", "summary, try editing" ), numericInput("obs", "sample observations:", 10, min = 1, max = 100 ) ), mainPanel( plotOutput("distPlot") ) ) ) server <- function(input, output, session) { output$distPlot <- renderPlot({ x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$nextgenshinyapps1 + 1 ) hist(x, breaks = bins, col = "blue", border = "gray" ) }) } shiny::shinyApp(ui = ui, server = server) }
library(shiny) library(shinyStorePlus) if (interactive()) { ui <- shiny::fluidPage( # initialize stores initStore(), titlePanel("Sample shinyStorePlus Init Inputs"), sidebarLayout( sidebarPanel( sliderInput("nextgenshinyapps1", "Number of bins:", min = 1, max = 200, value = 150 ), textInput( "caption", "simple caption:", "summary, try editing" ), numericInput("obs", "sample observations:", 10, min = 1, max = 100 ) ), mainPanel( plotOutput("distPlot") ) ) ) server <- function(input, output, session) { output$distPlot <- renderPlot({ x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$nextgenshinyapps1 + 1 ) hist(x, breaks = bins, col = "blue", border = "gray" ) }) } shiny::shinyApp(ui = ui, server = server) }
Parse the browser link and retrieve parameters for inclusion as values in inputs or outputs
link2input(..., inputtype = "default", session = getDefaultReactiveDomain())
link2input(..., inputtype = "default", session = getDefaultReactiveDomain())
... |
List of Shiny input IDs to match with window location parameters |
inputtype |
Type of inputs being included |
session |
Shiny session object |
Setting of the Shiny inputs to the values of the parameters in the browser link
a great example of how to use this functionality can be found in https://cran.r-project.org/web/packages/shinyStorePlus/vignettes/shinystoreplus_v08.html
if (interactive()) { # within the server function server <- function(input, output, session) { link2input( cd323 = "name", datasetbin = "data", numberid = "num" ) link2input( outputid = "outt", inputtype = "output" ) } }
if (interactive()) { # within the server function server <- function(input, output, session) { link2input( cd323 = "name", datasetbin = "data", numberid = "num" ) link2input( outputid = "outt", inputtype = "output" ) } }
Example of a shiny application with secure in-browser storage of inputs when changed
seeexample( name = c("storeInputs", "browserLinkToInput", "shinyWidgetsExamples") )
seeexample( name = c("storeInputs", "browserLinkToInput", "shinyWidgetsExamples") )
name |
the name of example to view. choices include storeInputs or browserLinkToInput or shinyWidgetsExamples |
An example of inputs persistently stored when changed and the page refreshed
Changes made to the input or putputs will be saved and returned when the page is refresh within the same browser over different sessions. More examples are located at https://github.com/oobianom/aagarw30_shinyapps_to-shinyStorePlus
if (interactive()) { seeexample() seeexample("browserLinkToInput") }
if (interactive()) { seeexample() seeexample("browserLinkToInput") }
Set up the application and inputs to track and retrieve stores
setupStorage( appId, inputs = TRUE, outputs = FALSE, session = getDefaultReactiveDomain(), dyn.inputs = list() )
setupStorage( appId, inputs = TRUE, outputs = FALSE, session = getDefaultReactiveDomain(), dyn.inputs = list() )
appId |
your desired application id |
inputs |
choose whether to track all inputs or specific input variables |
outputs |
choose whether to track all outputs or specific output variables |
session |
current session to track |
dyn.inputs |
dynamic inputs; inputs that get added to the app from the server function |
As of version 1.2, the user may be able to store dynamically generated inputs
Embed within a page storage that allows input changes to be saved without slowing down the shiny application
the inputs argument may be a TRUE
or FALSE
or a list of input ids. More examples are located at https://github.com/oobianom/aagarw30_shinyapps_to-shinyStorePlus