Skip to content

Can't use dbplyr in a shiny app #439

@daattali

Description

@daattali

Below is a simple reprex

library(shiny)
library(dplyr)

con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "cars", cars)

ui <- fluidPage(
  numericInput("speed", "speed", 15),
  tableOutput("table")
)

server <- function(input, output, session) {
  my_speed <- reactive({
    input$speed
  })
  
  output$table <- renderTable({
    tbl(con, "cars") %>%
      filter(speed == my_speed()) %>%
      collect()
  })
}

shinyApp(ui, server)

It produces an error no such function: my_speed. It looks like dbplyr thinks that my reactive is a database table? 😕 Note that if I save the reactive value to a local variable earlier and use that variable, then it does work. But it seems strange that I won't be able to use reactives in my sql, and I couldn't find any documentation suggesting this is expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions