Comments (4)
From the documentation:
When you replace the data in an existing table, please make sure the new data has the same number of columns as the current data.
So if you start with a NULL
dataset, it is expected that replaceData
will not work.
from dt.
That's what option 1. is supposed to simulate. If you populate the proxy with a dataset with no rows but that has the correct number of columns, the filters still don't work when data is updated and elongated.
from dt.
I think the reason can also be found in ?replaceData
:
When you have enabled column filters, you should also make sure the attributes of every column remain the same, e.g. factor columns should have the same or fewer levels, and numeric columns should have the same or smaller range, otherwise the filters may never be able to reach certain rows in the data, unless you explicitly update the filters with updateFilters().
from dt.
Thank you so much for this clarification. I believe updateFilters is what I'm looking for, but I've run into another issue with it though. I've modified the reprex above to include the modifications you suggested and with a wider dataset as is applicable to my use case. If you run the reprex, you'll notice very long processing time between when the button to populate the data is clicked and when the table actually renders. It also takes longer for just the empty table to show up. I only observe this behavior when the top filter is implemented. Once top filter is removed, the processing speed increases dramatically to populate the DT. Is this something that should be faster? On my actual shiny dashboard, it results in about 12-15 seconds of nothing happening, for a table of 3 row x 189 cols.
## added to load wide dataset (143 variables)
dat <- chickwts %>%
bind_rows(chickwts) %>%
mutate(name = paste0("col",row_number())) %>%
pivot_wider(id_cols = feed, names_from = name, values_from = weight)
shinyApp(
ui = fluidPage(
actionButton('showdata',"Show Data"),
actionButton('prev_five', 'Previous Cols'),
actionButton('next_five', 'Next Cols'),
DTOutput('tbl')),
server = function(input, output) {
cols <- reactiveValues()
cols$showing <- 1:3
# currently relies on observer to populate data
observeEvent(input$showdata,{
cols$df <- dat
})
# 1. use this to observe an empty dataset fed to proxy first
observe({
cols$df <- dat %>% filter(col1 == "test")
})
# 2. use this to observe a filled dataset fed to proxy first
# change matrix to only one or two rows to see the difference in tp filters that appear in the DT
# observe({
# # cols$df <- iris %>% filter(Species == "x")
# cols$df <- data.frame(matrix(1:10,nrow = 2,ncol = 5)) |>
# `colnames<-` (c(names(iris)))
# })
#show the next five columns
observeEvent(input$next_five, {
#stop when the last column is displayed
if(cols$showing[[length(cols$showing)]] < length(cols$df)) {
hideCols(proxy, cols$showing, reset = FALSE) #hide displayed cols
cols$showing <- cols$showing + 2
showCols(proxy, cols$showing, reset = FALSE) #show the next five
}
})
#similar mechanism but reversed to show the previous cols
observeEvent(input$prev_five, {
#stop when the first column is displayed
if(cols$showing[[1]] > 1) {
hideCols(proxy, cols$showing, reset = FALSE) #hide displayed cols
cols$showing <- cols$showing - 2
showCols(proxy, cols$showing, reset = FALSE) #show previous five
}
})
output$tbl = renderDT({
datatable(isolate(cols$df),filter = "top", # <- if this is commented out, this goes much more quickly
options = list(
columnDefs = list(list(visible = FALSE, targets = 1:length(isolate(cols$df)))), #hide all columns
scrollX = TRUE) #for when many columns are visible
)
})
proxy <- dataTableProxy('tbl')
observe({
DT::replaceData(proxy, cols$df, resetPaging = FALSE)
DT::updateFilters(proxy,cols$df)
})
showCols(proxy, 1:3, reset = FALSE) #show the first five cols (because the columns are now all hidden)
}
)
from dt.
Related Issues (20)
- Selection of multiple levels HOT 2
- [Accessibility] Trigger custom row select from Javascript callback HOT 11
- R shiny DT table with pagination and drop down list inside table and being able to save the entire updated table as csv file HOT 5
- DT 0.31 breaks previous 'ignore colnames' behavior during `replaceData()` HOT 1
- RowGroup extension with rownames = TRUE HOT 6
- updateSearch does not update numeric slider values
- datatable column filters clash with shiny::selectizeInput when invoked first HOT 4
- DateTime date picker CSS is broken in SearchBuilder
- Disabling editable table by row (and not just by column)
- autoFill extension returns `NaN` instead of incrementing HOT 5
- Docs do not state whether shift+click works for multi-row selection
- #828 breaks maintaining selected columns upon re-render HOT 3
- signif() + datatable() bug HOT 3
- `renderDT()` evaluates `...` in `expr`'s `env`
- Unable to test `renderDT()` in a `MockShinySession`
- First option entry ignored for default search values per column HOT 3
- Extract search functionality
- upgrade to datatables v2 HOT 2
- R Shiny application designed to navigate through multiple sections within a single page
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dt.