我在当地的R工作。但一旦我将它部署到shinyapps.io,它似乎就不起作用了。当我添加一些数据并重新打开应用程序时,以前添加的所有数据都消失了。
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)