I am new to asynchronous programming and would like to know if this is a proper way to use async programming in my app. I am having a data set that I am manipulating in a reactive and that will serve two different outputs, a table and a plot. In order to produce the correct outputs, I have to do some further manipulation for each output, plot and table. So can I store the promise in a temporary variable for the common manipulation both outputs need like I did below? In the example below I did not further wrangle the data frame but in my app I would to produce the right outputs. Thank you.
library(shiny)
library(promises)
library(future)
library(plotly)
library(DT)
library(shinyjs)
library(fastmap)
plan(multisession)
# Define UI for application that draws a histogram
ui <- fluidPage(
shiny::actionButton(inputId = "go", label = "go"),
br(),
plotly::plotlyOutput(outputId = "plot"),
DT::DTOutput(outputId = "table")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
shinyjs::click(id = "go")
data <- shiny::eventReactive(input$go, {
future_promise({mtcars})
})
out <- shiny::reactive({
data() %...>%
.[1:10, c("mpg", "wt")] -> some_commonly_used_df
some_commonly_used_df %...>%
plotly::plot_ly(x = ~mpg, y = ~wt) -> plot
some_commonly_used_df %...>%
DT::datatable() -> table
return(
list(
plot = plot,
table = table
)
)
})
output$table <- DT::renderDT({
out()$table
})
output$plot <- plotly::renderPlotly({
out()$plot
})
}
# Run the application
shinyApp(ui = ui, server = server)