How to capture shinyalert input field as variable

I'm trying to use the relatively new shinyAlert package to see if it offers better results than the sweetalert package but I'm unable to figure out how to get this:

Myvar <- shinyalert input text

from this minimal example.

library(shiny) library(shinyjs) library(shinyalert) ui <- fluidPage( shinyjs::useShinyjs(), useShinyalert(), actionButton("run", "Run", class = "btn-success") ) server <- function(input, output, session) { shinyEnv <- environment() observeEvent(input$run, { shinyalert('hello', type='input') }) } shinyApp(ui = ui, server = server)

My thanks for any help from you geniouses out there.


Here is how you do it:

library(shiny) library(shinyalert) ui <- fluidPage( useShinyalert(), actionButton("run", "Run", class = "btn-success") ) server <- function(input, output, session) { observeEvent(input$run, { shinyalert('hello', type='input', callbackR = mycallback) }) mycallback <- function(value) { cat(value) } } shinyApp(ui = ui, server = server)

It's done using callbacks. You can assign the value to a reactive variable if you'd like.

I had fully documented the package last month and was about to release it, and then my computer crashed before I had a chance to push to github, and lost all progress. I haven't had a chance to work on it again. So sorry that the documentation isn't great yet, the package is still un-released so use at your own risk for now :)

(Notice that you don't need shinyjs for this)


I have no experience with the package shinyalert, but you can achieve what you want with the widely used and well documented modal dialogs from shiny. Maybe you there is a reason for you to stick with shinyalert that I am unaware off, but if not, example code for achieving what you want with modal dialogs:

ui <- fluidPage( shinyjs::useShinyjs(), actionButton("run", "Run", class = "btn-success"), textOutput("output1") ) server <- function(input, output, session) { dataModal <- function(failed = FALSE) { modalDialog( textInput("input1", "Enter text:", placeholder = 'Enter text here' ) ) } # Show modal when button is clicked. observeEvent(input$run, { showModal(dataModal()) }) output$output1 <- renderText({ input$input1 }) } shinyApp(ui = ui, server = server)

Let me know if this helps!


  • Angular transclude in a directive containing a ng-template (generic Confirm Modal)
  • Eventbus onMessageEvent not getting called
  • Attemping to change attributes of $(this) inside success function
  • How to add regEx in angular filter
  • insert a picture into database(sqlite) with java code. what should i do?
  • How to synchronize two scrollview in Android?
  • Creating a Multi-Step Modal Using Jquery
  • Using android opencv apps without downloading opencv sdk manager
  • Google OAuth: can't get refresh token with authorization code
  • Add reference to ASP.NET 5 Class Library from Framework 4.5 Class Library Project
  • How to skip require in ruby?
  • Saving image to sd with current date and time in name doesn't work
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • How can I extract results of aggregate queries in slick?
  • Yii2: Config params vs. const/define
  • Get data from AJAX - How to
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Bug in WPF DataGrid
  • Volusion's generic SQL folder, functionality
  • Deserializing XML into class C#
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • How do you join a server to an Active Directory (domain)?
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • python draw pie shapes with colour filled
  • unknown Exception android
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • Unable to use reactive element in my shiny app
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?