简体   繁体   中英

r shiny eventReactive with promises

I am trying to use promises or some type of async in r shiny with mysql. I don't have a lot of users running this but as this scales up, I can see the need to use some type of promise? The following code is creating the query string in combination with dbGetQuery. If anyone has already answered this, please let me know.

tbl_selection <- eventReactive(input$go, {
  if ((input$Report) == "Report 1") {
    query <- paste0("select * from table where x=1")
  }
  else if ((input$Report) == "Report 2") { 
    query <- paste0("select * from table where x=2")
  }
  else if ((input$Report) == "Report 2") { 
    query <- paste0("select * from table where x=3")
  }

    dbGetQuery(con(), query)

})

Try this:

library(promises)
library(future)
plan(multisession)

myquery <- function(myinput){
  if (myinput == "Report 1") {
    query <- paste0("select * from table where x=1")
  }
  else if (myinput == "Report 2") { 
    query <- paste0("select * from table where x=2")
  }
  else if (myinput == "Report 3") { 
    query <- paste0("select * from table where x=3")
  }
  dbGetQuery(con(), query)
}


tbl_selection <- eventReactive(input$go, {
  future_promise({ 
    myquery(input$Report) 
  })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM