Me gustaría que mi servidor esperara hasta que algún Javascript devuelva un resultado. Considere el siguiente código de ejemplo
library(shiny) js <- ' Shiny.addCustomMessageHandler("bar", function(dummy) { Shiny.setInputValue("uniqueid", "Hello back"); } ' ui <- shinyUI(fluidPage(tags$script(js)), actionButton("foo", label = "Say hello"))) server <- shinyServer(function(input, output, session) { observeEvent(input$foo, { session$sendCustomMessage("bar", "hello") # it should wait here until uniqueid is no longer NULL print(input$uniqueid) }) }) shinyApp(ui, server)¿Cómo se puede lograr esto?
Puede agregar req() a la entrada:
library(shiny) jss <- 'Shiny.addCustomMessageHandler("bar", function(msg) { Shiny.setInputValue("uniqueid", "Hello back"); })' ui <- shinyUI( fluidPage( tags$script(jss), actionButton("foo", label = "Say hello") ) ) server <- shinyServer(function(input, output, session) { observeEvent(input$foo, { session$sendCustomMessage("bar", "hello") req(input$uniqueid) # it should wait here until uniqueid is no longer NULL print(input$uniqueid) }) }) shinyApp(ui, server)