-
Notifications
You must be signed in to change notification settings - Fork 33
Fixes the long-standing shiny modules problem #127
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
37a3243
Rename folder
andrie b96e119
Add shiny tests
andrie d1d3f81
Change from RStudio to Posit
andrie 613fda0
Fix shiny modules problem
andrie 719a324
Update project id
andrie b6d536c
Add shinytest2 artifacts
andrie 393cac2
Create vignette to explain fix for shiny modules
andrie 008ec35
Add shiny_modules.Rmd to pkgdown
andrie 4631125
Include shiny modules vignette in pkgdown site
andrie af55ff3
Include shiny modules vignette in pkgdown site
andrie 99deb0e
Bump version to 0.6.0
andrie c162bf6
Merge branch 'modules' of github.com:rstudio/sortable into modules
andrie 8ddf5df
`usethis::use_tidy_description()` (GitHub Actions)
andrie f23988c
`devtools::build_readme()` (GitHub Actions)
andrie 63fbd8e
Fix failing tests
andrie 7d16239
Merge branch 'modules' of github.com:rstudio/sortable into modules
andrie 57fff61
Fix failing tests
andrie 14b6a24
`devtools::document()` (GitHub Actions)
andrie f784d29
Skip shinytest2 tests on CI and CRAN
andrie 5505fa7
`devtools::document()` (GitHub Actions)
andrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,51 @@ | ||
| Type: Package | ||
| Package: sortable | ||
| Title: Drag-and-Drop in 'shiny' Apps with 'SortableJS' | ||
| Version: 0.5.0.9000 | ||
| Authors@R: | ||
| c(person(given = "Andrie", | ||
| family = "de Vries", | ||
| role = c("cre", "aut"), | ||
| email = "apdevries@gmail.com"), | ||
| person(given = "Barret", | ||
| family = "Schloerke", | ||
| role = "aut", | ||
| email = "barret@rstudio.com"), | ||
| person(given = "Kenton", | ||
| family = "Russell", | ||
| role = c("aut", "ccp"), | ||
| email = "kent.russell@timelyportfolio.com", | ||
| comment = "Original author"), | ||
| person("RStudio", role = c("cph", "fnd")), | ||
| person(given = "Lebedev", | ||
| family = "Konstantin", | ||
| role = "cph", | ||
| comment = "'SortableJS', https://sortablejs.github.io/Sortable/")) | ||
| Description: Enables drag-and-drop behaviour in Shiny apps, by exposing the | ||
| functionality of the 'SortableJS' <https://sortablejs.github.io/Sortable/> | ||
| JavaScript library as an 'htmlwidget'. | ||
| You can use this in Shiny apps and widgets, 'learnr' tutorials as well as | ||
| R Markdown. In addition, provides a custom 'learnr' question type - | ||
| 'question_rank()' - that allows ranking questions with drag-and-drop. | ||
| Version: 0.6.0 | ||
| Authors@R: c( | ||
| person("Andrie", "de Vries", , "apdevries@gmail.com", role = c("cre", "aut")), | ||
| person("Barret", "Schloerke", , "barret@posit.co", role = "aut"), | ||
| person("Kenton", "Russell", , "kent.russell@timelyportfolio.com", role = c("aut", "ccp"), | ||
| comment = "Original author"), | ||
| person("Posit", role = c("cph", "fnd")), | ||
| person("Lebedev", "Konstantin", role = "cph", | ||
| comment = "'SortableJS', https://sortablejs.github.io/Sortable/") | ||
| ) | ||
| Description: Enables drag-and-drop behaviour in Shiny apps, by exposing | ||
| the functionality of the 'SortableJS' | ||
| <https://sortablejs.github.io/Sortable/> JavaScript library as an | ||
| 'htmlwidget'. You can use this in Shiny apps and widgets, 'learnr' | ||
| tutorials as well as R Markdown. In addition, provides a custom | ||
| 'learnr' question type - 'question_rank()' - that allows ranking | ||
| questions with drag-and-drop. | ||
| License: MIT + file LICENSE | ||
| URL: https://rstudio.github.io/sortable/ | ||
| BugReports: https://github.com/rstudio/sortable/issues | ||
| Imports: | ||
| assertthat, | ||
| cli, | ||
| htmltools, | ||
| htmlwidgets, | ||
| jsonlite, | ||
| learnr (>= 0.10.0), | ||
| rlang (>= 1.0.0), | ||
| shiny (>= 1.9.0), | ||
| assertthat, | ||
| jsonlite, | ||
| utils, | ||
| rlang (>= 1.0.0) | ||
| utils | ||
| Suggests: | ||
| base64enc, | ||
| covr, | ||
| knitr, | ||
| testthat (>= 2.1.0), | ||
| withr, | ||
| rmarkdown, | ||
| magrittr, | ||
| webshot, | ||
| rmarkdown, | ||
| shinytest2, | ||
| spelling, | ||
| covr | ||
| testthat (>= 2.1.0), | ||
| webshot, | ||
| withr | ||
| VignetteBuilder: | ||
| knitr | ||
| Config/testthat/edition: 3 | ||
| Encoding: UTF-8 | ||
| Roxygen: list(markdown = TRUE) | ||
| RoxygenNote: 7.3.2 | ||
| Language: en-US | ||
| Config/testthat/edition: 3 | ||
| Roxygen: list(markdown = TRUE) | ||
| RoxygenNote: 7.3.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # TODO: Create demo app with modules | ||
| # TODO: Ensure module settings for id gets passed to JavaScript binding | ||
|
|
||
| # create environment for storing shiny module status | ||
| sortable_env = new.env() | ||
| sortable_env$modules = FALSE | ||
|
|
||
| #' Check if shiny modules are enabled for `sortable`. | ||
| #' | ||
| #' Due to an early (regrettable) design decision, `sortable` in versions <= 0.5.0 | ||
| #' did not support shiny modules. | ||
| #' To use `sortable` with shiny modules, you have to opt in to different | ||
| #' behaviour, by calling `enable_modules()`. | ||
| #' | ||
| #' @rdname modules | ||
| #' @return Logical value indicating whether shiny modules are enabled or not. | ||
| #' @export | ||
| is_modules_enabled <- function(){ | ||
| isTRUE(sortable_env$modules) | ||
| } | ||
|
|
||
| #' @rdname modules | ||
| #' @param enable If `TRUE`, enables modules. If `FALSE` disables them. | ||
| #' @export | ||
| enable_modules <- function(enable = TRUE){ | ||
| assertthat::assert_that(is.logical(enable)) | ||
| sortable_env$modules = enable | ||
| is_modules_enabled() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| ## ---- modules-app ----------------------------------------------------- | ||
| ## Example shiny app that dynamically updates a rank list | ||
|
|
||
| library(shiny) | ||
| library(sortable) | ||
| library(magrittr) | ||
|
|
||
| # shiny module ui ---- | ||
| mod_rank_list_ui <- function(id, text, labels) { | ||
| ns <- NS(id) | ||
| fluidRow( | ||
| rank_list(text, labels, input_id = ns("rank_list_1")), | ||
| verbatimTextOutput(ns("results")) | ||
| ) | ||
| } | ||
|
|
||
| # shiny module serevr ---- | ||
| mod_rank_list_server <- function(id) { | ||
| moduleServer(id, function(input, output, session) { | ||
| counter_bucket <- reactiveVal(1) | ||
|
|
||
| output$results <- renderPrint({ | ||
| input$rank_list_1 # This matches the input_id of the rank list | ||
| }) | ||
|
|
||
| observe({ | ||
| update_rank_list( | ||
| "rank_list_1", | ||
| text = paste("You pressed the update button", counter_bucket(), "times"), | ||
| ) | ||
| counter_bucket(counter_bucket() + 1) | ||
| }) %>% | ||
| bindEvent(input$btnUpdateRank) | ||
|
|
||
|
|
||
| observe({ | ||
| update_rank_list( | ||
| "rank_list_1", | ||
| labels = sample(LETTERS, 5) | ||
| ) | ||
| }) %>% | ||
| bindEvent(input$btnChangeLabels) | ||
|
|
||
| observe({ | ||
| update_rank_list( | ||
| "rank_list_1", | ||
| labels = list() | ||
| ) | ||
| }) %>% | ||
| bindEvent(input$btnEmptyLabels) | ||
|
|
||
| observe({ | ||
| update_rank_list( | ||
| "rank_list_1", | ||
| labels = sort(input$rank_list_1) | ||
| ) | ||
| }) %>% | ||
| bindEvent(input$btnSortLabels) | ||
|
|
||
| }) | ||
| } | ||
|
|
||
|
|
||
| # shiny ui ---- | ||
| ui <- fluidPage( | ||
| tags$head( | ||
| tags$style(HTML(".bucket-list-container {min-height: 350px;}")) | ||
| ), | ||
| fluidRow( | ||
| column( | ||
| width = 12, | ||
| h2("Modify a rank list"), | ||
| actionButton("btnUpdateRank", label = "Update rank list title"), | ||
| actionButton("btnChangeLabels", label = "Change labels"), | ||
| actionButton("btnSortLabels", label = "Sort labels"), | ||
| actionButton("btnEmptyLabels", label = "Empty labels") | ||
| ) | ||
| ), | ||
| fluidRow( | ||
| column( | ||
| width = 6, | ||
| h2("Rank list A"), | ||
| mod_rank_list_ui( | ||
| id = "rl1", | ||
| text = "Change the order", | ||
| labels = letters[1:5] | ||
| ) | ||
| ), | ||
| column( | ||
| width = 6, | ||
| h2("Rank list B"), | ||
| mod_rank_list_ui( | ||
| id = "rl2", | ||
| text = "Second order", | ||
| labels = LETTERS[6:10] | ||
| ) | ||
| ) | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| # shiny server ---- | ||
| server <- function(input, output, session) { | ||
| mod_rank_list_server("rl1") | ||
| results_2 <- mod_rank_list_server("rl2") | ||
| } | ||
|
|
||
| shinyApp(ui, server) |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| Version: 1.0 | ||
| ProjectId: f5b175a3-1218-4e55-8f73-192b92827f27 | ||
|
|
||
| RestoreWorkspace: Default | ||
| SaveWorkspace: Default | ||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "output": { | ||
| "results": "[1] \"a\" \"b\" \"c\" \"d\" \"e\"" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "output": { | ||
| "results": "[1] \"W\" \"C\" \"R\" \"F\" \"I\"" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "output": { | ||
| "results": "[1] \"a\" \"b\" \"c\" \"d\" \"e\"" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "output": { | ||
| "results": "NULL" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "output": { | ||
| "results": "[1] \"M\" \"I\" \"Z\" \"W\" \"Q\"" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this constant messaging and inconsistent behavior is harder to understand than a big "BREAKING CHANGE, all your sortable DOM IDs have been updated. <previous_format> is now <new_format>. You only need to worry if you have custom css. Thank you for your patience as we have learned from our mistakes." in the NEWS.md
This would remove the startup message, remove the sortable_env, remove the vignette for inconsistent behavior.
I'd rather lean towards "at version X, the behavior changed to something simple and expected".