在Shiny App中刷新RDS文件

时间:2018-08-26 14:57:58

标签: r shiny rhandsontable

我正在闪亮的应用程序中编辑rhandsontable,并将结果保存在RDS文件中。最初,该文件是在global.R文件中读取的:

DF <- readRDS("data/tcdatapythian/TCComb.Rds")

然后在server.R中,我正在使用以下代码来生成rhandsontable

values <- reactiveValues()

## Handsontable
observe({
  if (!is.null(input$TCData)) {
    values[["previous"]] <- isolate(values[["DF"]])
    DF = hot_to_r(input$TCData)
    DF <- DF[1:nrow(DF),]
    DF[,12] <- DF[,11] %m+% months(DF[,9])
    DF[,15] <- DF[,12] - DF[,10]
    DF[,16] <- DF[,12] + DF[,10]
    DF[,17] <- DF[,15] - DF[,13]
    DF[,14] <- as.numeric(DF[,17] - Sys.Date())
  } else {
    if (is.null(values[["DF"]]))
      DF <- DF
    else
      DF <- values[["DF"]]
  }
  values[["DF"]] <- DF
})

output$TCData <- renderRHandsontable({
  DF <- values[["DF"]]
  if (!is.null(DF))
    rhandsontable(DF) %>% hot_cols(colWidths = 200, fixedColumnsLeft=1)

})

然后,用户可以通过单击保存(savetc)按钮来编辑表并保存更改:

## Save
observeEvent(input$savetc, {

  finalDF <- isolate(values[["DF"]])
  saveRDS(finalDF, "data/tcdatapythian/TCComb.Rds")

}
)

数据已保存在RDS文件中,但是如果用户刷新浏览器,它仍会显示先前未编辑的数据。如何使用保存的更改刷新RDS文件?

以下是一些示例数据:

structure(list(Vessel = c("ACAMAR", "ACAMAR", "ACAMAR", "Asterion", 
"Asterion", "Atria"), `IMO Number` = c(9587817L, 9587817L, 9587817L, 
9595125L, 9595125L, 9595137L), `Vessel Type` = c("SHTP", "SHTP", 
"SHTP", "SHTP", "SHTP", "SHTP"), `CP Date` = structure(c(17694, 
17694, 17694, 17694, 17694, 16968), class = "Date"), `JV Partner` = c(NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
), `Period Type` = c("First", "Option 1", "Option 2", "First", 
"Option", "First"), `Laycan From` = c(NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_), 
    `Laycan To` = c(NA_character_, NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_), `Period in Months` = c(12L, 
    6L, 6L, 12L, 12L, 6L), `+/- Period Days` = c(30L, 30L, 30L, 
    30L, 30L, 30L), Delivery = structure(c(17785, 18150, 18332, 
    17868, 18233, 16983), class = "Date"), `Anniversary Date` = structure(c(18150, 
    18332, 18516, 18233, 18599, 17165), class = "Date"), `Option Days` = c(30L, 
    30L, 30L, 30L, 30L, 30L), `Days to Option Declaration` = c("323", 
    "505.5", "687.5", "406", "771", "-662"), `Earliest Re-Delivery` = structure(c(18120, 
    18302, 18484, 18203, 18568, 17135), class = "Date"), `Latest Re-Delivery` = structure(c(18180, 
    18362, 18546, 18263, 18629, 17195), class = "Date"), `Date for Exercising option` = structure(c(18090, 
    18272, 18454, 18173, 18538, 17105), class = "Date"), Redelivery = structure(c(17967, 
    17967, 17967, 18233, NA, 17165), class = "Date"), `Redelivery Area` = c(": UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN", 
    ": UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN", 
    ": UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN", 
    "UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN", 
    "UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN", 
    "<U+200B>UKC / MED <U+2013> CARIBS / USG / USAC / ECMEX / ECAN"
    ), `Redel Notices` = c("30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery", 
    "30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery", 
    "30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery", 
    "30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery", 
    "30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery", 
    "30/20/15/12 days approximate and 10/7/5/3/2/1 days definite notice of redelivery"
    ), `Earliest Redelivery Notice` = c(NA_character_, NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_
    ), Rate = c(12100, 13100, 13100, 12100, 13100, 13500), `CVE per month` = c(NA_real_, 
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), `Add Commission` = c(0, 
    0, 0, 0, 0, 0.0125), `Broker Commission` = c(0, 0, 0, 0.0125, 
    0.0125, 0.0125), Owners = c("Acamar Holdings S.A. Luxembourg", 
    "Acamar Holdings S.A. Luxembourg", "Acamar Holdings S.A. Luxembourg", 
    "Asterion Acquisition S.A. Luxembourg<U+00A0>", "Asterion Acquisition S.A. Luxembourg<U+00A0>", 
    "Atria Acquisition S.A., Luxembourg"), Charterers = c("Estoril", 
    "Estoril", "Estoril", "Estoril", "Estoril", "Estoril"), Remarks = c(NA_character_, 
    NA_character_, NA_character_, NA_character_, NA_character_, 
    NA_character_)), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

0 个答案:

没有答案