0

The following shiny app works the first time you run it, but then errors if you change the species input because the table name already exists in memory. I was wondering how to set overwrite == TRUE given the code below?

library(shiny)
library(tidyverse)
library(dbplyr)

ui <- fluidPage(
    selectInput("species", "Species", choices = unique(iris$Species), 
                selected = "setosa"),
    tableOutput("SQL_table"),
    actionButton("code", "View SQL"),
)


server <- function(input, output) {

    # render table
    output$SQL_table <- renderTable(
        head(iris %>% filter(Species == input[["species"]]))
    )

    # generate query
    SQLquery <- reactive({
        sql_render(
            show_query(
                tbl_memdb(iris) %>%
                filter(Species == local(input$species))
            )
        )
    })

    # see query
    observeEvent( input$code, {
        showModal(
            modalDialog(
                SQLquery()
            )
        )
    })
}


shinyApp(ui = ui, server = server)
MayaGans
  • 1,815
  • 9
  • 30

1 Answers1

1

since memdb_frame is just a function call of copy_to we can use it directly to set overwrite = TRUE

copy_to(src_memdb(), iris, name = 'iris', overwrite=TRUE)
MayaGans
  • 1,815
  • 9
  • 30