jrowen / rhandsontable

A htmlwidgets implementation of Handsontable.js
http://jrowen.github.io/rhandsontable/
Other
385 stars 148 forks source link

Character column transformed to numeric in hot_to_r #421

Open chabrault opened 2 years ago

chabrault commented 2 years ago

I have an issue using hot_col with a specified list of character elements, for some elements. In some cases, the column class is transformed to numeric despite a list of character elements is provided.

Minimal reproducible example:

library(rhandsontable)
shinyApp(
  ui = basicPage(
    tagList(
      h4("Character transformed to numeric"),
      rhandsontable::rHandsontableOutput("t1"),
      verbatimTextOutput("o1"),

    )
  ),

  server = function(input, output, session) {
    # transformed to numeric if the first two elements are selected
    char_source <- c("0001E","0006E","0002A")
    output$t1 <- rhandsontable::renderRHandsontable({
      rhandsontable::rhandsontable(data.frame(character = c(rep(NA,5)))) %>%
        rhandsontable::hot_col(col="character",type="dropdown",
                               source=char_source, format="character") 

    })
    output$o1 <- renderPrint({
      str(rhandsontable::hot_to_r(input$t1))
    })
  }
)

In this example, the source is composed of character elements. If the first two elements are chosen ("0001E" or "0006E"), the column class is transformed to numeric. This does not happen if the last element is selected ("0002A") or if the data frame is initially defined with "" instead of NA.

Thank you for this nice package.