我正在尝试通过hot_to_r将rhsonsontable对象转换为r对象,但是我发现我的表具有date列,并且由于该原因,它向我抛出了一个错误:“没有强制将“字符”转换为“ NA的方法或默认值” ”。我尝试删除date列,但没有它,它运行正常。知道如何解决此问题吗?
这是遇到相同问题的示例代码
library(shiny)
library(shinydashboard)
library(rhandsontable)
ui <- dashboardPage(skin = 'green',
dashboardHeader( title = "TD Securities", titleWidth = 280),
dashboardSidebar(width = 280 ),
dashboardBody(
fluidRow(
column(4,
helpText("editable table"),
rHandsontableOutput("table"),
br(),
actionButton("saveBtn","Save"))
)))
server <- shinyServer(function(input, output) {
# creat a table with date column
mtcars1<- transform(mtcars,date = Sys.Date())
# returns rhandsontable type object - editable excel type grid data
output$table <- renderRHandsontable({
rhandsontable( mtcars1) # converts the R dataframe to rhandsontable object
})
# on click of button the file will be saved to the working directory
observeEvent(input$saveBtn, {
write.csv(hot_to_r(), file = "MyData.csv",row.names = FALSE)})
# hot_to_r() converts the rhandsontable object to r data object
})
shinyApp(ui, server)