bobtao
August 11, 2021, 12:42pm
1
The following works OK:
output$summary_dt1 <- renderReactable({
cars <- MASS::Cars93[1:20, c("Manufacturer", "Model", "Type", "Price")]
data <- SharedData$new(cars)
# bscols(
# widths = c(3, 9),
# list(
# filter_checkbox("type", "Type", data, ~Type),
# filter_slider("price", "Price", data, ~Price, width = "100%"),
# filter_select("mfr", "Manufacturer", data, ~Manufacturer)
# ),
reactable(data, minRows = 10)
# )
})
But if I'd like to use the filters by uncommenting the commented lines (by itself the bscols works fine in a console) , nothing is showing up ina Shiny app. Any pointers is appreciated?
The issue here is probably that the reactable function returns a different object than the bscols. I am not sure since you haven't posted your UI. If you use renderUI en uiOutput it does work.
library(shiny)
library(reactable)
library(crosstalk)
ui <- fluidPage(
titlePanel("My reactable"),
mainPanel(
uiOutput("summary_dt1")
)
)
server <- function(input, output) {
output$summary_dt1 <- renderUI({
data <- mtcars
bscols(
widths = c(3, 9),
list(),
reactable(data, minRows = 10)
)
})
}
shinyApp(ui = ui, server = server)
bobtao
August 11, 2021, 2:29pm
4
Now how could I access what are selected?
library(shiny)
library(DT)
library(reactable)
library(crosstalk)
cars <- copy(mtcars)
dt0 <- SharedData$new(cars)
ui <- fluidPage(
titlePanel("My reactable"),
tabsetPanel(id='inTabSet',
tabPanel("DT1", uiOutput("dt1")),
tabPanel("DT2", DT::dataTableOutput("dt2"))
)
)
server <- function(input, output) {
output$dt1 <- renderUI({
bscols(
widths = c(3,9),
list(
filter_checkbox("cyl", "CYL", dt0, ~cyl),
filter_slider("drat", "DRAT", dt0, ~drat, width = "100%"),
filter_select("am", "AUTO", dt0, ~am)
),
reactable(dt0,
filterable = TRUE, searchable = TRUE
,selection = "multiple", selectionId = "selected", striped = T, onClick = "select"
,resizable = TRUE, wrap = FALSE, bordered = TRUE, compact = TRUE
,minRows = 5
)
)
})
selected_y1 <- reactive(getReactableState("dt1", "selected"))
selected_dt1 <- reactive({
dt0[selected_y1(),]
})
output$dt2 <- renderDT({
selected_dt1()
})
}
shinyApp(ui = ui, server = server)
Apparently, selected_y1, selected_dt1 do not work.
bobtao
August 11, 2021, 7:23pm
5
# If I use
output$x <- renderReactable ({.....})
# I can do
selected_x <- reactive(getReactableState("x", "selected"))
# now with dt0 inside reactable within output$dt1
# how would I access the selected rows
system
Closed
October 4, 2021, 11:23pm
6
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.