OctoCatKnows
OctoCatKnows

Reputation: 419

Why is RShiny shinyalert (callback) not rendering?

I am using the example from Dean's shinyalert package:

library(shiny)
library(shinyalert)

shinyApp(
ui = fluidPage(
useShinyalert(),  # Set up shinyalert
actionButton("btn", "Greet")
     ),

server = function(input, output) {

observeEvent(input$btn, {
  shinyalert(
    "Enter your name", type = "input",
    callbackR = function(x) { message("Hello ", x) },
    callbackJS = "function(x) { alert('Hello ' + x); }"
  )
})
 }
 )

pic2 pic3

For some reason, the example shown on the github does not work on mine. And when I remove the callbackJS. Nothing happens. I input the name and click 'Ok' but the chain modal does not work.

chainmodal

Any ideas?

Upvotes: 1

Views: 1854

Answers (1)

Tonio Liebrand
Tonio Liebrand

Reputation: 17699

I think you have to use:

    callbackR = function(value) { shinyalert(paste("Welcome", value))}

It might also been what is shown in the docu: https://github.com/daattali/shinyalert#chaining.

Your code message("Hello ", x), actually works as designed since it prints the message to the console.

Full code would read:

library(shiny)
library(shinyalert)

shinyApp(
  ui = fluidPage(
    useShinyalert(),  # Set up shinyalert
    actionButton("btn", "Greet")
  ),

  server = function(input, output) {

    observeEvent(input$btn, {
      shinyalert(
        "Enter your name", type = "input",
        callbackR = function(value) { shinyalert(paste("Welcome", value))},
        callbackJS = "function(x) { alert('Hello ' + x); }"
      )
    })
  }
)

Upvotes: 2

Related Questions