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

can't display a lazy tbl #464

Closed
ilyaminati opened this issue Nov 1, 2017 · 3 comments
Closed

can't display a lazy tbl #464

ilyaminati opened this issue Nov 1, 2017 · 3 comments
Milestone

Comments

@ilyaminati
Copy link

ilyaminati commented Nov 1, 2017

When the data source is a tbl_lazy from dplyr, DT fails to render, returns error message.

Error in datatable: 'data' must be either a matrix or a data frame

There's no error with shiny::renderTable, because it calls collect(). But DT::renderDataTable should not call collect() on the whole data source, because its rendered data table can be paginated and filtered, i.e., the data can be collected lazily.

con <- DBI::dbConnect(...) # same with pool::dbPool(...)

ui <- fluidPage(
  DT::dataTableOutput("tbl")
)

server <- function(input, output, session) {
  dat <- reactive({
    con %>%
      tbl("mytable"))
  })

  output$tbl <- DT::renderDataTable({
    dat()
  })
}

shinyApp(ui, server)
@shrektan
Copy link
Collaborator

shrektan commented Jan 5, 2018

Sorry I'm confused of what you are expecting.

Why not call collect() and pass a data.frame to DT::renderDataTable()?

Also, call collect() automatically for tbl_lazy only saves one command but it may cause troubles if the table in the database is very large.

@ilyaminati
Copy link
Author

There are two parts here.

  1. Bug: the error message is unclear. It would be helpful to suggest that the user should call collect() when the input is a tbl_lazy.

  2. Request for enhancement: when the input is a tbl_lazy, in interactive mode, in the R console, the input still displays ten lines of the tibble. Similarly, DT could display ten lines, and provide a button to display ten more lines, i.e., paginate the lazy tibble. DT already paginates a non-lazy tibble by default, so this would extend pagination to the lazy tibble.

@yihui
Copy link
Member

yihui commented Jan 16, 2018

We can certainly improve the error message.

For 2, I think it is more challenging but is what I was interested to do (#194). Currently DT does not take advantage of databases at all, and it definitely should. The implementation is probably not trivial, though.

@yihui yihui added this to the v0.3 milestone Jan 16, 2018
@yihui yihui mentioned this issue Jan 16, 2018
3 tasks
@yihui yihui closed this as completed in bfba046 Jan 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants