0

I have a question regarding R shiny and the observ function. Is it possible to save the selected factors and the state of the work? I would like to close and reopening the program and select then my previously saved state with the selected factors load, once to have a kind of memory, but not again to select all factors.

Does anyone have an idea? Thank you for your help!

Edit a Example: In the example I generate a Choice of factores, which i can choose in the App. Now I want to save the choice and load it next time.

shinyServer(function(input, output, session) {


  myData <- reactive({
    inFile <- input$file1

    factors <- colnames(myData)   # get the names of the Factors in a Vector to select them
    v$choices <- input$letters  # append(v$choices,input$letters)
    updateSelectInput(session, "letters",
                      choices = factors #[!factors %in% v$choices)]

    if (is.null(inFile)) {
      return(NULL) }

    if (input$fileType_Input == "1") {
      read.csv2(inFile$datapath,
                header = TRUE,
                stringsAsFactors = FALSE)

    } else {
      read_excel(inFile$datapath)
    }

  })


  observe({
    if(is.null(input$letters)){
      data <- myData()
      factors <- colnames(data)   # get the names of the Factors in a Vector to select them
      v$choices <- input$letters  # append(v$choices,input$letters)
      updateSelectInput(session, "letters",
                        choices = factors #[!factors %in% v$choices)]
      )
    }
  })


  #Display a Summary of the data
  output$summary <- renderTable({

    data <- myData()
    subsetData <- subsetOfData(data, v$choices)
    summary <- summaryFactors(subsetData)
  })



ui <- fluidPage(
  navbarPage(title=div(img(src="D:/Aktuelles/WZL_WiHi_ab/Inputs/wzl_rgb_png"), "Willkommen"),
             tabPanel("Aufbereitung",
                      sidebarLayout(
                        sidebarPanel(
                          radioButtons(
                            "fileType_Input",
                            label = h5("Waehlen Sie hier das Dateiformat der Daten die Sie einlesen wollen."),
                            choices = list(".csv" = 1, ".xlsx" = 2),
                            selected = 1,
                            inline = TRUE
                          ),

                          fileInput('file1', ''  ),

                          h5("Bitte geben Sie an welche Faktoren in der Zusammenfassung angezeigt werden sollen:"),

                          selectInput("letters", label=NULL, factors, multiple = TRUE)

                        ),
                        mainPanel(

                            tabPanel("Zusammenfassung",

                                     tableOutput("summary")
                            )
                          )
                        )
                      )
             ),


  )
)

I hope it is now easier to understand.

Zorro
  • 91
  • 1
  • 8
  • It is not really clear what you are asking to me. Please add a [reproducible example](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable/48343110#48343110) and use that to describe the desired behavior, – Florian Mar 29 '18 at 08:11
  • Edit: I hope it is now easier to understand. – Zorro Mar 29 '18 at 09:58
  • AFAIK, you will have to define your own logic for saving/loading the data to/from disk. See [here](https://shiny.rstudio.com/articles/persistent-data-storage.html). If you only want to save inputs (ui selections), [this approach](https://shiny.rstudio.com/articles/bookmarking-state.html) can also be used. – Gregor de Cillia Mar 29 '18 at 19:45
  • Thank you! Yes I want to save inputs (ui selections) and learned a lot about bookmarking my states, but I have an other Problem. I realize that my fileInputs are saved only when the state are saved to server. But now I also want to save the state which are generated from my Inputfile, such as "colnames(myData)" in my example. Do you have an idea? – Zorro Mar 30 '18 at 18:38

0 Answers0