In brilliant state, you can call client-side callbacks written in javascript from server logic. Let's say in ui.R you have JavaScript, including a function called setText :
tags$script(' Shiny.addCustomMessageHandler("setText", function(text) { document.getElementById("output").innerHTML = text; }) ')
then in server.R you can call session$sendCustomMessage(type='foo', 'foo') .
Suppose I have a long-term function that returns some data to build. If I do this normally, thread R is busy during the execution of this function and therefore cannot process additional requests during this time. It would be very useful to be able to run this function using a futures package so that it runs asynchronously with the code and calls the callback asynchronously. However, when I tried, it just didn't work.
Sorry if this is not very clear. As a simple example, you need to follow these steps until you uncomment the two lines trying to call the future in server.R . Once these lines are uncommented, the callback will never be called. Obviously, this is not really useful in the context of this example, but I think it would be very useful in general.
ui.R :
library(shiny) shinyUI(fluidPage( sidebarLayout( sidebarPanel( sliderInput("max", "Max random number:", min = 1, max = 50, value = 30) ), mainPanel( verbatimTextOutput('output'), plotOutput('plot') ) ), tags$script(' Shiny.addCustomMessageHandler("setText", function(text) { document.getElementById("output").innerHTML = text; }) ') ))
server.R :
library(shiny) library(future) plan(multiprocess) shinyServer(function(input, output, session) { output$plot <- reactive({ max <- input$max