Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny lost colnames & numeric to factor after edit #35

Closed
marciz opened this issue Oct 2, 2019 · 3 comments
Closed

Shiny lost colnames & numeric to factor after edit #35

marciz opened this issue Oct 2, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@marciz
Copy link
Contributor

marciz commented Oct 2, 2019

Describe the bug
After shiny table edit (e.g. put char 'a' into Sepal.Length):

  • lost colnames when column param used (no issue if columns = NULL)
  • if character value input into numeric, column is converted to factor

To Reproduce
Steps to reproduce the behavior:

library(shiny)
library(excelR)

dt <- iris[1:10,]
dt$Species <- as.character(dt$Species)
dt$date <- Sys.Date()

shinyApp(
  ui = fluidPage(excelOutput("table")),
  server = function(input, output, session) {
    rv <- reactiveValues(
      dt = dt
    )
    output$table <- renderExcel(
      excelTable(data = rv$dt, 
                 columns = data.frame(
                   title = colnames(rv$dt),
                   type = excelR:::get_col_types(rv$dt)
                 ))
    )
    observeEvent(input$table,{
      str(rv$dt)
      xls <- excel_to_R(input$table)
      rv$dt <- xls
      str(rv$dt)
    })
  }
)

'data.frame': 10 obs. of 6 variables:
$ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9
$ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1
$ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5
$ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1
$ Species : chr "setosa" "setosa" "setosa" "setosa" ...
$ date : Date, format: "2019-10-02" "2019-10-02" "2019-10-02" ...
'data.frame': 10 obs. of 6 variables:
$ : Factor w/ 7 levels "4.4","4.6","4.7",..: 7 4 3 2 5 6 2 5 1 4
$ : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1
$ : num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5
$ : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1
$ : chr "setosa" "setosa" "setosa" "setosa" ...
$ : Date, format: "2019-10-02" "2019-10-02" "2019-10-02" ...

other attached packages:
[1] excelR_0.3.1 shiny_1.3.2

Is there a way to limit character input into numeric column? So that only numeric values are accepted. Date columns already don't allow character input

@marciz
Copy link
Contributor Author

marciz commented Oct 3, 2019

To avoid character input in numeric fields, probably need to add mask parameter to column data.frame. If it is numeric then it might be mask:'#.#' by default

@Swechhya
Copy link
Owner

Swechhya commented Oct 3, 2019

@marciz Thank you for reporting the issue. I'll look into the issue of why column names are getting lost after edit. and why the numeric value is getting converted to factor instead of character. Should be related to one of the recent changes made in excel_to_R function.

I'll see if jexcel provides an extension to restrict the number/character input into columns. Could you file a new feature request for this so that I can work on it in the upcoming version?

@Swechhya Swechhya added the bug Something isn't working label Oct 9, 2019
@Swechhya
Copy link
Owner

@marciz, the above two PR should resolve the issues you have reported. You can reopen this if the issue you have reported hasn't been addressed in latest development version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants