rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
599 stars 180 forks source link

Possible bug in dataTableProxy - reloadData functions #650

Closed MajinKLS closed 5 years ago

MajinKLS commented 5 years ago

First of all I'm new in this comunity so greetings to all members ;). I search about my problem but I did not found any issue like the one I own. As is a simple scenario I doubt a bit of being a real bug. Maybe I'm doing something wrong or is a environment issue.

A bit of context: I'm working in a project where I make a csv file and pass it to R environment. Then this data is rendered with a customized DT object. After rendering the DT a proxy is made. The Shiny application have some controls to change the decimal precision of some columns of the table. This is done by getting the original data in R environment (wich have max decimal precision), the data is edited with round function and then reloaded into de previous rendered table using the proxy and reloadData function.

image

The issue The help of reloadData function says: ... must have exactly the same number of columns as the previous data object in the table.

My reloaded data have exactly the same number of columns and they are exactly of the same datatype. When I reload the full table I get the following message : No matching records found

image

I discovered that this happens everytime I load the first column. If I load a all the table except for the first column I get the data and all filters works, except for the first one (I guess it is because it have no data). Despite of no load his data, this column perserve the original values adding 1 to them, so if first register is zero after reload is one.

image

Here is my R environment: platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.2
year 2018
month 12
day 20
svn rev 75870
language R
version.string R version 3.5.2 (2018-12-20) nickname Eggshell Igloo

And the description of my dataframe:

'data.frame': 1450 obs. of 10 variables: $ Index : int 0 1 2 3 4 5 6 7 8 9 ... $ NodeIndex : int 1 2 3 4 5 6 7 8 9 10 ... $ NodeLabelID: Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ... $ Time : int 0 0 0 0 0 0 0 0 0 0 ... $ TimeStep : int 600 600 600 600 600 600 600 600 600 600 ... $ Demand : num 0.1 0.3 0.15 0.2 0 0.25 0 0 0 -1 ... $ Head : num 53.5 53.5 53.5 53.5 53.5 ... $ Pressure : num 50.5 51.5 50 50.5 51.5 ... $ Quality : num 0 0 0 0 0 0 0 0 0 25 ... $ SourceMass : logi NA NA NA NA NA NA ...

DT package versions: 0.4 and 0.5

Finally here my customization of DT object:

`setMethod(f="resultsTable", signature="DrawEpanet", def=function(Object, resultsTable, roundableColumns, tableHeight) {

          columnsIndexes <- c(0:length(colnames(resultsTable))-1) 
          remove <-c(1,2,3)
          ninjaColumns <- columnsIndexes [! columnsIndexes %in% remove]
          optionsForDT <- function() {
            list(
              dom ='lftB',
              autoWidth = FALSE,
              scrollY = tableHeight,
              scrollX = TRUE,
              paging = FALSE,
              dom = 'Bfrtip',
              buttons = list(list(extend = 'colvis', columns = ninjaColumns),
                          'copy',
                          'csv',
                          'excel',
                          'pdf'),
              columnDefs = list(list(className = 'dt-right', targets = 0:length(colnames(resultsTable))-1),
                                list(searchable = FALSE, targets = c(0))
                                ),
              stateSave = FALSE,
              ordering=FALSE,
              server=TRUE
            )
          }

          DT <-  DT::datatable(resultsTable,
                               rownames= FALSE,
                               filter = list(position = 'top', plain = TRUE),
                               extensions = 'Buttons',
                               selection = list(target = 'column', mode = 'single'),
                               options = optionsForDT()) %>% formatRound(columns=roundableColumns, dec.mark = ",", digits = 5)

          return(DT::renderDataTable(DT))
        }

)`

Thanks for your help. I hope my post is useful. Best regards

shrektan commented 5 years ago

Would you please take some time to make a minimal reproducible example?

MajinKLS commented 5 years ago

Hi, I made the most simple reproducible code in my scenario. Doing this I detected that the problem is with the property "rownames=FALSE". I think long time ago I read something about an issue with this property but not related with the reloadData function.

In my project there's no need to correlation between indexes in both applications (the source of CSV file and Shiny), so a solution for me is to not load my "Index" column and replace it by DT row index.

I guess we can upload reproducible codes and example files somewere in this github. Meanwhile I uploaded it into GoogleDrive: https://drive.google.com/file/d/1FD7MEnj3DgpScueY9ToQ_dVLYTbSnxSv/view?usp=sharing

It includes a CSV example file with spanish separation and decimal character.

Best regards,

MajinKLS commented 5 years ago

Hi just found that my issue was duplicated. This post talks about the same problem.

403

I close the post.