Closed tylerlittlefield closed 2 years ago
This is actually a good question. With the hindsight of some distance from the project it's clear that the documentation is ambiguous.
The sortable_output()
and render_sortable()
functions are only useful if you want to create custom functions that wrap the sortable
JS library.
In your case it seems you simply want to embed a rank_list()
into your app. To do this, all you need is the rank_list()
in your UI code, without any server code. Thus a rank_list()
is somewhat similar to a radioButtons()
or selectInput()
- it's simply a mechanism to capture inputs.
Let me know if I misunderstood your question and you actually want to build a custom HTMLwidget using sortable
.
I think I was looking for update functions, something like updateRankListOuput
or updateRankListInput
. My particular use case it to allow users to rearrange the columns of their dataset, so the sortable labels need to be dynamic. I was able to achieve what I want with uiOutput
:
library(shiny)
ui <- fluidPage(
selectInput("data", "data", c("mtcars", "iris"), "mtcars"),
uiOutput("sortable"),
tableOutput("table")
)
server <- function(input, output, session) {
rv <- reactiveValues(data = data.frame())
observeEvent(input$data, {
rv$data <- get(input$data)
})
observeEvent(input$sortable, {
rv$data <- rv$data[input$sortable]
})
output$sortable <- renderUI({
sortable::rank_list("", names(rv$data), "sortable")
})
output$table <- renderTable({
rv$data
})
}
shinyApp(ui, server)
That seems like a sensible approach for your use case. May I re-use this example in a vignette?
Of course! ☺️
We fixed this in #67
When testing this vignette locally, the options aren't able to be dragged after rendering them with renderUI
. Is this a known issue?
How do the shiny render functions work? I couldn't find any documentation on the topic. Below is my attempt: