Closed topepo closed 3 years ago
Here's an updated example that uses reactable
:
# See
# https://glin.github.io/reactable/articles/examples.html
# ------------------------------------------------------------------------------
library(shiny)
library(reactable) # remotes::install_dev("reactable")
library(crosstalk)
library(tidymodels)
tidymodels_prefer()
# ------------------------------------------------------------------------------
# Example from tune: calculate and reformat performance metrics for each candidate
# model
performance <-
ames_grid_search %>%
collect_metrics() %>%
dplyr::relocate(metric = .metric, estimate = mean) %>%
dplyr::select(-.estimator, -n, -std_err)
# ------------------------------------------------------------------------------
# Make a shared data source; don't show .config in the table but keep in original data
.perf <- SharedData$new(performance %>% dplyr::select(-.config))
sticky_style <- list(backgroundColor = "#f7f7f7")
# ------------------------------------------------------------------------------
ui <- fluidPage(
title = "Examples of DataTables",
sidebarLayout(
sidebarPanel(
verbatimTextOutput('chosen_config')
),
mainPanel(
h3("Select a performance metric:"),
filter_checkbox("metric_select", "", .perf, ~metric, inline = TRUE),
h3("Select a tuning parameter combination:"),
reactableOutput("metrics")
)
)
)
server <- function(input, output) {
output$metrics <- renderReactable({
reactable(
.perf,
filterable = TRUE,
selection = "single",
defaultColDef = colDef(
cell = function(value) format(value, digits = 3, scientific = FALSE)
),
columns = list(
metric = colDef(
sticky = "left",
style = sticky_style,
headerStyle = sticky_style
),
estimate = colDef(
sticky = "left",
style = sticky_style,
headerStyle = sticky_style
)
),
bordered = TRUE,
highlight = TRUE
)
})
output$chosen_config = renderPrint({
chosen_config <- performance$.config[getReactableState("metrics", "selected")]
cat("I choose:\n", chosen_config, "\n")
})
}
shinyApp(ui, server)
Merged to main in the recent PR. For now we are using DT::datatable
, but we will look into reactable
as an alternate.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
The
autoplot()
method for selecting a tuning parameter looks nice but is a bit complex and kludgy to use.Instead, we might want to use an interactive table where users can click on a row to get the candidate model that they like.
Here's a simple example:
This looks like: