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 t
Here is POC of how to make the user input consistent across sessions.
DPUT and DGET are the two commands to make the it work. So you end up with a local file that stores the value of the input variable. Here I am only making the input$dataset variable consistent. I think you can use more advance command or even database if you have more variables.. but this works for one is fairly easy.
Since I have been playing with this a few iterations between server.R and ui.R and I probably you might need to initialize the file at the beginning for one time through command line or even build some logical in your code to check if the file exist or not, if not, create a new file with some default value.
server.R
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
dput(input$dataset, "inputdata_dataset")
})
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Shiny Text"),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars"),
selected = dget("inputdata_dataset")),
numericInput("obs", "Number of observations to view:", 10)
),
mainPanel(
verbatimTextOutput("summary"),
tableOutput("view")
)
))
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.
Sorry, it took me a while. Thanks for all the answers.
I kinda found a workaround (I'll be posting only the relevant parts of my code). I found the solution using conditionalpanel. In my app the user has to define the settings before he starts the calculations and it was crucial that he saves them first (various reasons, mainly reproducibility). So I created a tabpanel for each step in the calculation and my quite simple solution was that every tabpanel relies on the save button. The result is that the user can't even start the calculation before he hasn't saved the settings.
shinyUI(navbarPage(title=div(img(src="---", height=72, width=72, align="left")), theme ="bootstrap.css", fluid=T,
tabPanel("Startseite",
tags$head(tags$script(HTML('
Shiny.addCustomMessageHandler("jsCode",
function(message) {
console.log(message)
eval(message.code);
}
);
'))),
actionButton("Ja",
label="Neue Berechnung beginnen",
icon("upload",lib="font-awesome")),
actionButton("Nein",
label="Bestehende Berechnung laden",
icon("upload",lib="font-awesome"))),
tabPanel("Einstellungen", progressInit(),
conditionalPanel(condition="input.Ja > 0",
wellPanel(actionButton("save",
label="Einstellungen speichern",
icon("save",lib="font-awesome")
),
br(),
br(),
navlistPanel("Einstellungen",
tabPanel("Interne Kalibrierung",
conditionalPanel(condition="input.save> 0",
wellPanel(actionButton("freqbutton", "Frequenzschätzung durchführen"),
plotOutput("freqPlot")
),
wellPanel(actionButton("intthresbutton", "Berechnung der internen Threshold"),
dataTableOutput("IntTable")
))
),