So you want to have a button, and when you click on it, both the javascript function and some R code are called? I was able to do this using the onclick function from shinyjs package (disclaimer: I wrote the package)
library(shinyjs) jsCode <- " shinyjs.geocodeAddr = function(params) { alert('JavaScript called!'); // geocodeAddressStreet(...) } " runApp(shinyApp( ui = fluidPage( useShinyjs(), extendShinyjs(text = jsCode), actionButton("btn", "Click me") ), server = function(input, output, session) { onclick("btn", { js$geocodeAddr() cat("R called as well") }) } ))
Basically, the onclick function is an R function that will run when a button is clicked. Inside it, you can obviously easily call the R code, but you can also call the JS code using the shinyjs package - like I made a call to js$geocodeAddr . Take a look at the extendShinyjs function. Alternatively, instead of using extendShinyjs() you can also use the usual session$sendCustomMessage(...) approach
source share