-
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
let expand button execute a renderPlot function #367
Comments
I think there are a few different ways to answer this. So first, there's currently no officially supported way to take an action when a user expands a row. It should eventually be supported in the JavaScript API, but for now, it's an undocumented feature that may still change in the future. If you want to try this with the risks, here's a quick example of watching for expanded state changes using library(shiny)
data <- MASS::Cars93[, c("Manufacturer", "Model", "Type", "Price")]
ui <- fluidPage(
reactableOutput("tbl"),
verbatimTextOutput("tbl_state")
)
server <- function(input, output) {
output$tbl <- renderReactable({
tbl <- reactable(
data,
details = function(index) paste("Details for row", index),
searchable = TRUE
)
htmlwidgets::onRender(tbl, "() => {
Reactable.onStateChange('tbl', state => {
const { expanded } = state
Shiny.setInputValue('tbl_expanded', { expanded })
})
}")
})
output$tbl_state <- renderPrint({
writeLines("Table expanded rows (zero-based indices):\n")
print(input$tbl_expanded)
})
}
shinyApp(ui, server) The custom Or to sidestep the expand button completely, you could potentially render a different, row or column-specific output$plot_row_1 <- renderPlot({ ... })
details = function(index, column) {
plotOutput(paste0("plot_row_", index))
} And finally, a completely different solution that I often see with drill down style tables is to put the plot completely outside of the table, and use row selection to control what the plot shows. This would be a lot simpler to implement today, and can avoid some of the awkward UX with having lots of information in expanded row details. |
Your correct on this. That is why I wanted to have full control over understanding which row was expanded or not. Thanks for the solution with Reactable.onStateChange.
Indeed that's the easiest but a bit less integrated way in my point of view. |
I'm trying to see if I can make a row expandable and in the same time when clicking the expand button that it updates the plot based on the information in that button which is clicked.
By using the following code.
If I click on the column which has that expand button the onClick event is not triggered.
I would like to be able to update the plot when a user clicks the expand button. How would you do that? It looks like this is currently not supported or maybe I'm missing something?
Video_240327162620.mp4
The text was updated successfully, but these errors were encountered: