Rhandsontable удаляет столбцы - PullRequest
       58

Rhandsontable удаляет столбцы

0 голосов
/ 25 февраля 2019

У меня есть очень простой фрейм данных в rhandsontable с несколькими пустыми столбцами.

При открытии пустые столбцы исчезали, а сохранение катастрофично при исчезновении этих столбцов.

это ожидаемое поведение?

Просто откройте этот CSV и посмотрите на файл ПОСЛЕ использования rhandsontable на нем.

column1,column2,column3
1,,some
2,,thing
3,,disappeared

library(rhandsontable)
library(shiny)


fname <- "data" 
values <- list()
setHot <- function(x) values[["hot"]] <<- x


ui <- shinydashboard::dashboardPage(dashboardHeader(title = "Removing columns you wanted?",  titleWidth = 990)
                                    dashboardSidebar(disable = TRUE),
                                    dashboardBody(rHandsontableOutput("hot"),
                                                  br(),
                                                  actionButton("saveBtn", "Save changes")
                                    ))

server <- function(input, output, session) {

  observe({
    input$saveBtn # update csv file each time the button is pressed
    if (!is.null(values[["hot"]])) { # if there's a table input
      #write.csv(values[["hot"]], fname) # overwrite the temporary database file
      write.csv(x = values[["hot"]], file = 'data.csv', row.names = FALSE) # overwrite thecsv
    }

  })

  output$hot <- renderRHandsontable({
    if (!is.null(input$hot)) { # if there is an rhot user input...
      DF <- hot_to_r(input$hot) # convert rhandsontable data to R object and store in data frame
      setHot(DF) # set the rhandsontable values

    } else {
      DF <- rio::import('data.csv', stringsAsFactors = FALSE)

      setHot(DF) # set the rhandsontable values
    }

    rhandsontable(DF)

  }
  )

}

shinyApp(ui = ui, server = server)
...