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

Add example to README of rich content in rank_list #31

Closed
colearendt opened this issue Jul 20, 2019 · 1 comment · Fixed by #40
Closed

Add example to README of rich content in rank_list #31

colearendt opened this issue Jul 20, 2019 · 1 comment · Fixed by #40

Comments

@colearendt
Copy link

colearendt commented Jul 20, 2019

It took me a little while to understand enough to build a (silly) example, so I think it would be worthwhile showing how to build rich content inside of a rank_list! (Probably with a more interesting example)

library(shiny)
library(sortable)

ui <- fluidPage(

    titlePanel("Old Faithful Geyser Data"),

    fluidRow(
        bucket_list(
            header = "Hello",
            add_rank_list(
                text = "List 1",
                input_id = "list_1",
                labels = c(
                    list(tags$div(tags$b("Hi"), tags$br(), tags$b("Two"))), 
                    "Hello"
                    )
            ),
            add_rank_list(
                text = "List 2",
                input_id = "list_2",
                labels = NULL
            ),
            add_rank_list(
                text = "List 3",
                input_id = "list_3",
                labels = c("two")
            ),
            add_rank_list(
                text = "List 4",
                input_id = "list_4",
                labels = c("three")
            )
        )
    ),
    fluidRow(textOutput("presentation"))
)

server <- function(input, output) {
  output$presentation <- renderText(
      capture.output(str(input$list_1))
  )
}

shinyApp(ui = ui, server = server)

However, I will say that the Shiny input does not seem to be initialized properly at the start (requires moving something to get the inputs working), and it would be nice to have some hooks into what is returned. I.e. if I could define my own ID for each label and have that returned.

image

After moving something:

chr [1:2] "Hi \nTwo\n" "Hello"

(I believe this is because of the following, which does not fire until sorted:)

sortable_options(onSort = sortable_js_capture_input(input_id)),

However, if you want a "hidden" ID or something, you can use font-size: 0 as a trick 😄

add_rank_list(
                text = "List 1",
                input_id = "list_1",
                labels = c(
                    list(tags$div(tags$span(id = "test", "test", style = "font-size: 0"), tags$b("Hi"), tags$br(), tags$b("Two"))), 
                    "Hello"
                    )
            )

# results in:
chr [1:2] "test Hi \nTwo\n" "Hello"
@colearendt
Copy link
Author

NOTE: This is where the values are coerced to text, and could be extended / replaced by a user (like me) 😄

sortable_js_capture_input <- function(input_id) {
inner_text <- "
$.map(this.el.children, function(child){return child.innerText})
"
js_text <- "function(evt){{
if (typeof Shiny !== \"undefined\") {
Shiny.onInputChange(\"%s\", %s)
}
}}"
js <- sprintf(js_text, input_id, inner_text)
htmlwidgets::JS(js)
}

andrie added a commit that referenced this issue Feb 26, 2021
* Capture error if bucket_list header is empty #31

* Remove context() statements from tests

* Use testthat 3rd edition.

* Fix rank-list-item that spills outside the container boundary #68

* Allow bucket_list to have empty header, and capture error better #69

* Revert to `header = NULL` as default; improve handling of is_header()

* Update is_header() with suggested assertions

Co-authored-by: Barret Schloerke <barret@rstudio.com>

* Update R/bucket_list.R after code review

Co-authored-by: Barret Schloerke <barret@rstudio.com>

Co-authored-by: Barret Schloerke <barret@rstudio.com>
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

Successfully merging a pull request may close this issue.

1 participant