mirai.promises
makes ‘mirai’ ‘promises’ for easy integration in ‘plumber’ or ‘shiny’ pipelines.
mirai.promises
also supports nanonext
‘recvAio’ asynchronous message receives.
Install the latest release from CRAN:
install.packages("mirai.promises")
or the development version from rOpenSci R-universe:
install.packages("mirai.promises", repos = "https://shikokuchuo.r-universe.dev")
The below example simulates a plot function requiring a long compute in a ‘shiny’ app.
This app takes c. 2s to start compared to the 8s it would otherwise take if the ‘long-running’ computations were not running on parallel workers.
The auxiliary function polling()
may be used to customise the frequency with which to poll for promise resolution (defaults to every 100 ms).
Package authors wishing to use the S3 methods contained within this package may simply import the polling()
function to make them available.
library(mirai.promises)
library(shiny)
polling(freq = 50L)
# set 4 persistent workers
daemons(n = 4L)
ui <- fluidPage(
fluidRow(
plotOutput("one"),
plotOutput("two"),
),
fluidRow(
plotOutput("three"),
plotOutput("four"),
)
)
make_plot <- function(time) {
Sys.sleep(time)
runif(10)
}
args <- list(make_plot = make_plot, time = 2)
server <- function(input, output, session) {
output$one <- renderPlot(mirai(make_plot(time), .args = args) %...>% plot())
output$two <- renderPlot(mirai(make_plot(time), .args = args) %...>% plot())
output$three <- renderPlot(mirai(make_plot(time), .args = args) %...>% plot())
output$four <- renderPlot(mirai(make_plot(time), .args = args) %...>% plot())
session$onSessionEnded(stopApp)
}
shinyApp(ui = ui, server = server)
Daniel Falbel for the original version of the above example and agreeing to its use here, as well as the specific use case that motivated this package.
mirai.promises
on CRAN: https://cran.r-project.org/package=mirai.promises
mirai
website: https://shikokuchuo.net/mirai/mirai
on CRAN: https://cran.r-project.org/package=mirai
- High Performance Computing CRAN Task View: https://cran.r-project.org/view=HighPerformanceComputing
nanonext
website: https://shikokuchuo.net/nanonext/nanonext
on CRAN: https://cran.r-project.org/package=nanonext
–
Please note that the mirai.promises project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.