rhandsontable 中允许的日期格式
第一个问题是格式date
柱子。这好像是POSIXct
这里不允许。根据rhandsontable 的 github 文档, Date
as in Sys.Date()
被推荐。所以更换
date.range <- as.POSIXct((seq(start.date,end.date,by="day")), origin = "1970-01-01")
with
date.range <- as.Date((seq(start.date,end.date,by="day")), origin = "1970-01-01")
解决了这个问题。警告
警告:as 中的错误:没有方法或默认值将“字符”强制为“NA”
通过调用创建hot_to_r
现在应该消失了。
同时更新两个表
为了进行所有更改table1
affect table2
反之亦然,您可以使用相同的反应值在服务器端存储表。
这是一个完整的工作解决方案。
library(shiny)
library(rhandsontable)
channel <- c("TV","Radio","Digital")
start.date <- as.Date("2017-01-01")
end.date <- as.Date("2017-01-07")
date.range <- as.Date((seq(start.date,end.date,by="day")), origin = "1970-01-01")
date.range <- as.data.frame(date.range)
colnames(date.range) <- c("date")
date.range[channel] <- 0
table1 <- date.range
table2 <- date.range
#Define the tables.
ui <- fluidPage(
br(),
fluidRow(
column(4, rHandsontableOutput("table1output")),
column(4, rHandsontableOutput("table2output"))
))
server <- function(input,output,session){
table <- reactiveValues()
table$table1 <- table1
#DEFINE ONLY TABLE1
output$table1output <- renderRHandsontable({rhandsontable(table$table1)})
output$table2output <- renderRHandsontable({rhandsontable(table$table1)})
#rhandsontable outputs
observeEvent(input$table1output,{
df <- hot_to_r(input$table1output)
df <- as.data.frame(df)
table$table1 <- df
}, ignoreInit = TRUE, ignoreNULL = TRUE
)
#if a user updates table1 table2 should also update.
observeEvent(input$table2output,{
df <- hot_to_r(input$table2output)
df <- as.data.frame(df)
table$table1 <- df
}, ignoreInit = TRUE, ignoreNULL = TRUE
)
#if a user updates table2 table1 should also update.
}
shinyApp(ui = ui, server = server)