I'm trying to construct an arrow query inside of a shiny server function, and running into the error object '.dependents' not found, which appears to be coming from the R6 OOP system (e.g. Reactive within R6 classes throws .dependents not found error · Issue #137 · r-lib/R6 · GitHub).
Here's a reprex, where data2 creates the error:
library(shiny)
library(dplyr)
library(arrow)
arrow::write_dataset(iris[-1, ], "iris.parquet")
ui <- fluidPage(
fluidRow(
selectInput(
inputId = "species",
choices = unique(iris$Species),
selected = "setosa",
multiple = TRUE,
label = "Species"
)
),
fluidRow(h2("data:"), DT::DTOutput("data")),
fluidRow(h2("data2:"), DT::DTOutput("data2"))
)
server <- function(input, output, session) {
con = arrow::open_dataset("iris.parquet")
output$data =
con |>
filter(Species %in% input$species) |>
collect() |>
DT::renderDataTable()
# why doesn't this work?
cur_species = reactive(input$species)
output$data2 =
con |>
filter(Species %in% cur_species()) |>
collect() |>
DT::renderDataTable()
}
shinyApp(ui, server)
Supposing I'm committed to creating cur_species as an intermediate reactive (because in my actual application, computing cur_species requires multiple complicated steps): is there a way to make this approach work? Thanks for any advice!