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

Why selection is disabled when creating datatable outside shiny? #1043

Closed
3 tasks done
bartekch opened this issue Jan 2, 2023 · 2 comments
Closed
3 tasks done

Why selection is disabled when creating datatable outside shiny? #1043

bartekch opened this issue Jan 2, 2023 · 2 comments

Comments

@bartekch
Copy link

bartekch commented Jan 2, 2023

I've noticed that if datatable is created outside Shiny environment, selection is completely ignored, thanks to inShiny() call. I'm wondering what is the motivation behind this, because I was a bit surprised by this. In particular in the following example I would expect default selection mode to be working, but it's not.

library(shiny)
library(DT)
dt_outside <- DT::datatable(mtcars)
shinyApp(
    ui = basicPage(DT::DTOutput("dt")),
    server = function(input, output) {
        output$dt <- DT::renderDT(dt_outside)
    }
)

I don't see any specific reason why it is so, and I feel that sometimes it could be useful (for the record - I don't have real use case, I noticed it by accident while experimenting with some other features). Ot maybe you are not supposed to use it like that?

Session info

─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 22621)
 system   x86_64, mingw32
 ui       Rgui
 language (EN)
 collate  Polish_Poland.utf8
 ctype    Polish_Poland.utf8
 tz       Europe/Warsaw
 date     2023-01-02
 pandoc   NA

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 bslib         0.4.2   2022-12-16 [1] CRAN (R 4.2.2)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.2.2)
 callr         3.7.3   2022-11-02 [1] CRAN (R 4.2.2)
 cli           3.5.0   2022-12-20 [1] CRAN (R 4.2.2)
 crayon        1.5.2   2022-09-29 [1] CRAN (R 4.2.2)
 crosstalk     1.2.0   2021-11-04 [1] CRAN (R 4.2.2)
 devtools      2.4.5   2022-10-11 [1] CRAN (R 4.2.2)
 digest        0.6.31  2022-12-11 [1] CRAN (R 4.2.2)
 DT          * 0.26    2022-10-19 [1] CRAN (R 4.2.2)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.2)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.2)
 fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.2)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.2)
 htmltools     0.5.4   2022-12-07 [1] CRAN (R 4.2.2)
 htmlwidgets   1.6.0   2022-12-15 [1] CRAN (R 4.2.2)
 httpuv        1.6.7   2022-12-14 [1] CRAN (R 4.2.2)
 jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.2.2)
 jsonlite      1.8.4   2022-12-06 [1] CRAN (R 4.2.2)
 later         1.3.0   2021-08-18 [1] CRAN (R 4.2.2)
 lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.2)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.2)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.2.2)
 mime          0.12    2021-09-28 [1] CRAN (R 4.2.0)
 miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.2.2)
 pkgbuild      1.4.0   2022-11-27 [1] CRAN (R 4.2.2)
 pkgload       1.3.2   2022-11-16 [1] CRAN (R 4.2.2)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.2.2)
 processx      3.8.0   2022-10-26 [1] CRAN (R 4.2.2)
 profvis       0.3.7   2020-11-02 [1] CRAN (R 4.2.2)
 promises      1.2.0.1 2021-02-11 [1] CRAN (R 4.2.2)
 ps            1.7.2   2022-10-26 [1] CRAN (R 4.2.2)
 purrr         1.0.0   2022-12-20 [1] CRAN (R 4.2.2)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.2)
 Rcpp          1.0.9   2022-07-08 [1] CRAN (R 4.2.2)
 remotes       2.4.2   2021-11-30 [1] CRAN (R 4.2.2)
 rlang         1.0.6   2022-09-24 [1] CRAN (R 4.2.2)
 sass          0.4.4   2022-11-24 [1] CRAN (R 4.2.2)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.2)
 shiny       * 1.7.4   2022-12-15 [1] CRAN (R 4.2.2)
 stringi       1.7.8   2022-07-11 [1] CRAN (R 4.2.1)
 stringr       1.5.0   2022-12-02 [1] CRAN (R 4.2.2)
 urlchecker    1.0.1   2021-11-30 [1] CRAN (R 4.2.2)
 usethis       2.1.6   2022-05-25 [1] CRAN (R 4.2.2)
 vctrs         0.5.1   2022-11-16 [1] CRAN (R 4.2.2)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.2.2)
 yaml          2.3.6   2022-10-18 [1] CRAN (R 4.2.2)

 [1] C:/Users/bartosz.chrol/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.2/library

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@yihui
Copy link
Member

yihui commented Jan 3, 2023

You can set options(DT.datatable.shiny = TRUE to bypass the inShiny() check.

I think the original rationale was that you can't do anything meaningful with the selections without Shiny (or crosstalk). The only possible use case I can think of is to highlight certain parts of a table.

The example you provided is indeed surprising. Our inShiny() check may be too strict. I'll soften it in a minute. Thanks!

@yihui yihui closed this as completed in ec6060c Jan 3, 2023
@bartekch
Copy link
Author

bartekch commented Jan 3, 2023

Yes, highlighting may be useful, perhaps for some presentation purposes.

Thanks for the quick fix, I could confirm it's working :)

AhmedKhaled945 pushed a commit to AhmedKhaled945/DT that referenced this issue Jul 5, 2023
… really inside a Shiny app

e.g., a datatable() may be created outside shinyApp() but used in shinyApp() later, in which case we should enable selection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants