Skip to content

Doesn't work properly with shinytest2 #123

@averissimo

Description

@averissimo

I cannot use sortable in shinytests2 as it doesn't print correctly, nor does it capture the events for use in shiny.

Even when explicitly using htmltools::as.tags to print the sortable_js it fails (see below on 2nd example)

Reproducible examples

1. Minimal example of failure:

  • Show object's text instead of rendering tags
  • Drag & drop doesn't work
ui <- shiny::fluidPage(
  shiny::tagList(
    shiny::tags$p("You can drag and reorder the items in this list:"),
    shiny::tags$ul(
      id = "example_1",
      shiny::tags$li("Move"),
      shiny::tags$li("Or drag"),
      shiny::tags$li("Each of the items"),
      shiny::tags$li("To different positions")
    ),
    sortable::sortable_js(css_id = "example_1")
  )
)

server <- function(input, output, session) { }

testapp <- shiny::shinyApp(ui, server)
app <- shinytest2::AppDriver$new(testapp)
app$view()

Image

2. Workaround failure of registering handler event

ui <- shiny::fluidPage(
  shiny::tagList(
    shiny::tags$p("You can drag and reorder the items in this list:"),
    shiny::tags$ul(
      id = "example_1",
      shiny::tags$li("Move"),
      shiny::tags$li("Or drag"),
      shiny::tags$li("Each of the items"),
      shiny::tags$li("To different positions")
    ),
    htmltools::as.tags(
      sortable::sortable_js(
        css_id = "example_1",
        options = sortable::sortable_options(
          onSort = sortable::sortable_js_capture_input("reporter_cards_order")
        )
      )
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$reporter_cards_order, {
    # This will print the new order of the items in the console
    print(input$reporter_cards_order)
  })
}

testapp <- shiny::shinyApp(ui, server)
app <- shinytest2::AppDriver$new(testapp)

# Drag & drop an element
app$get_logs()
#> {shiny}      R  stderr ----------- Error in (function (name, val, shinysession)  : 
#> {shiny}      R  stderr -----------   No handler registered for type reporter_cards_order:sortablejs.rank_list

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions