I created a simple app where you can input some data and add it to a dataframe. When I close the app and open it once again, the data added before should be displayed.
I got this working in R locally. But once I deployed it to shinyapps.io it does not seem to work. When I add some data and re-open the app, all the previously added data is gone.
My guess is that it does not save to the 'global environment' on shinyapps.io but am unsure since I am new to deploying this type of apps.
Below is a reproducible example.
library(shiny)
library(DT)
data <- data.frame(title = character(), start = as.Date(character()), end = as.Date(character()),
stringsAsFactors=FALSE)
ui <- function(){fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
dateInput("date",
label = "Date"),
selectInput("from", "From", choices = c("08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30",
"12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30",
"16:00", "16:30")),
selectInput("until", "Until", choices = c("08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30",
"12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30",
"16:00", "16:30"), selected = "16:30"),
actionButton("add", "Add")
),
mainPanel(
tabsetPanel(
tabPanel("Table", DT::dataTableOutput("table"))
)
)
)
)}
server <- function(input, output) {
values_data <- reactiveValues()
values_data$df <- data
addData <- observeEvent(input$add, {
newLine <- isolate(data.frame(title = paste(input$from, " - ", input$until), start = as.Date(input$date)
, end = as.Date(input$date)))
values_data$df <- isolate(rbind(values_data$df, newLine))
data <<- values_data$df
})
output$table <- DT::renderDataTable({
datatable(values_data$df, editable = FALSE)
})
}
shinyApp(ui, server)