Error in eval: object 'rows' not found. when using future package with glue package in shiny app

After upgrading to R 3.6.0 and maybe some package, the app using promises showing error: Warning: Error in eval: object 'rows' not found

Below is the code of app. See it online in shinyapps.io also.


library(shiny)
library(glue)
library(promises)
library(future)
plan(multiprocess)

ui <- fluidPage(

    # Application title
    titlePanel("test promises in shiny"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("rows",
                        "Number of rows:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        mainPanel(
           textOutput("session"),
           tableOutput('table')
           
        )
    )
)

server <- function(input, output) {
    
    df <- reactive({
        rows <- input$rows
        future({
            con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
            DBI::dbWriteTable(con, "mtcars", mtcars)
            query <- glue_sql("select * from mtcars limit {rows}", .con = con)
            dbGetQuery(con, query)
        })
    })

    output$table <- renderTable({
        df()
    })
    
    output$session <- renderPrint({
        sessionInfo()
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

EDIT: I open an issue in future github rep too. See here

@shizidushu Thank you for the reprex!

Running your app, I ran into no errors. I'd recommend uninstalling / reinstalling any app that was compiled with R 3.5.*.

Updated App:

library(shiny)
library(glue)
library(promises)
library(future)
plan(multiprocess)

ui <- fluidPage(

    # Application title
    titlePanel("test promises in shiny"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("rows",
                        "Number of rows:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        mainPanel(
           verbatimTextOutput("session"),
           tableOutput('table')
           
        )
    )
)

server <- function(input, output) {
    
    df <- reactive({
        rows <- input$rows
        future({
            con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
            DBI::dbWriteTable(con, "mtcars", mtcars)
            query <- glue_sql("select * from mtcars limit {rows}", .con = con)
            DBI::dbGetQuery(con, query)
        })
    })

    output$table <- renderTable({
        df()
    })
    
    output$session <- renderPrint({
        sessioninfo::session_info()
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

Working output:

This is not a bug and it's expected.

> https://github.com/HenrikBengtsson/future/issues/308#issuecomment-492313713

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.