闪亮的记忆保留(加载数据)

时间:2018-06-05 04:08:06

标签: r shiny

尊敬的人,

我想在保存和加载数据方面提供一些帮助。我创建了一个shinyapp,其中创建了一个rhandsontable,用户可以输入该值。但问题是当我关闭窗口并重新运行代码时,我没有得到用户输入的值,而是默认值。这意味着我无法保存或检索旧信息。能否帮我解决这个问题,因为我对这个平台非常陌生。我附上了我的程序代码。请帮我解决这个问题。我的目标是当我关闭并重新运行程序时,我应该能够看到之前输入的值。

 library(shiny)
 library(shinyFiles)
 library(readr)
 library(shinydashboard)
 library(rhandsontable)
header<-dashboardHeader()

sidebar <- dashboardSidebar()

#Creation of Tabs

body <- dashboardBody(
tabBox( width=12,
            tabPanel("Table",
                     rHandsontableOutput("hot"),
                     br(),
                     br(),
                     actionButton("save","Save changes")
            ),

            tabPanel("Demand/Capacity Plot",
                     plotOutput("dc","Demand Capacity Plot",width="50%", height="700px")
            )
    )
  )

  ui <- dashboardPage(header,sidebar=sidebar,body=body)

  # Creation empty dataframe table_l1

  table_l1<data.frame(Months=1:14,Bt_existing=numeric(14),
  Output_hr=numeric(14),stringsAsFactors = FALSE)

  #To make the dataframe reactive
  server <- function(input, output, session){
  prev_tabl_l1 <- reactive({table_l1})
  aftch_tabl_l1<- reactive({

  if (is.null(input$hot)){
   return(prev_tabl_l1())

      } else if(!identical(prev_tabl_l1(),input$hot)){
        table_l1<-as.data.frame(hot_to_r(input$hot))
        table_l1[,3]<-3600/table_l1[,2]
        table_l1 
      }
    })


# Creation of rHandsontable
output$hot <- renderRHandsontable({
  rhandsontable (aftch_tabl_l1(),rowHeaders =c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Year 1","year 2"),width= 500, height=200,selectCallback = TRUE) %>%

 hot_table(rowHeaderWidth = 200) %>%
 hot_col(1,readOnly = TRUE)

})

}

 shinyApp(ui=ui, server=server)

0 个答案:

没有答案