-
Notifications
You must be signed in to change notification settings - Fork 80
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
Get sorting state in Shiny #265
Comments
Hi, that's not possible with There is a a way to get sorted state in the JavaScript API though, using |
I want to export the table data in a special format (an Excel file with added metadata), and I would like to keep the sorting done by the user in the export. Here's my code using the JavaScript API : library(shiny)
library(reactable)
# custom handler otherwise JSON is over simplified
registerInputHandler("reactable_sort", function(x, ...) {
x
}, force = TRUE)
ui <- fluidPage(
downloadButton(
"downloadData", "Download",
onClick = "Shiny.setInputValue('table_state:reactable_sort', Reactable.getState('cars_table').sorted)"
),
reactableOutput("cars_table"),
verbatimTextOutput("test")
)
server <- function(input, output) {
output$cars_table <- renderReactable({
reactable(MASS::Cars93)
})
output$test <- renderPrint(input$table_state)
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
data <- if (is.null(input$table_state)) {
MASS::Cars93
} else {
data <- MASS::Cars93
table_state <- input$table_state
for (i in rev(seq_along(input$table_state))) {
col <- table_state[[i]]$id
desc <- table_state[[i]]$desc
data <- data[order(data[[col]], decreasing = isTRUE(desc)), ]
}
data
}
write.csv(data, file)
}
)
}
shinyApp(ui, server) |
And then I also added a way to listen on table state changes in the JavaScript API, so you can send table state to Shiny even if
|
Hello,
Is it possible to get sorting options in a shiny application ? On which columns is the table sorted and in which order.
Something like :
will be great !
The text was updated successfully, but these errors were encountered: