I have quite a problem. I'm trying to run a program with quite a few different settings, which can be set in the ui. In my case the user may need to run the programm with the same settings more than once. My Problem is that if you refresh or restart the UI everything is set to the default values. For example:
numericInput("1",
label = h4("...."),
4,
min=1,
max=100,
step=1
),
br(),
numericInput("2",
label = h4("..."),
1000000,
min=1,
max=100000000,
step=1
)
If I set the numericInput "1" to 7, and rerun the program it will be by default at 4. Due to the fact that i have quite a few of those settings, this can be quite a buzzkill. So my question is:"Is there a way to save the changes i have made?"
thank you:)
This is a tricky subject. It maybe best to have a client side solution. HTML5 allows the use of local storage. There are a number of javascript libraries which have simple api's for this. I have put a wrapper around one of them as proof of concept:
devtools::install_github("johndharrison/shinyStorage")
library(shinyStorage)
library(shiny)
runApp(
list(
ui = fluidPage(
addSS(),
uiOutput("textExample")
)
, server = function(input, output, session){
ss <- shinyStore(session = session)
output$textExample <- renderUI({
myVar <- ss$get("myVar")
if(is.null(myVar)){
textInput("textID", "Add some text to local storage")
}else{
textInput("textID", "Add some text to local storage", myVar)
}
})
observe({
if(!is.null(input$textID)){
if(input$textID != ""){
ss$set("myVar", input$textID)
}
}
})
}
)
)
So the demo doesnt look like much. Input some text in the textInput box refresh your browser and the text is remembered hip hurrah!!! The approach can be extended for any R list like objects upto 10mb in size. I will tinker some more on the package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With