Easy way to show an error: use javascript alert from server.R

215 views
Skip to first unread message

Dmitri

unread,
Jan 23, 2014, 7:28:12 AM1/23/14
to shiny-...@googlegroups.com
I often need to alert the user that nothing was run because of incorrect input. Instead of trying to show an error message inside a data.frame using renderDataTable(), for example, or keeping a separate output object for that, I came up with a way to show a javascript alert from server.R. Here is an example for those unfamiliar with addCustomMessageHandler(), who need similar functionality.

Add the following to ui.R:

tags$script(type="text/javascript", "
   $(document).ready(function() {
        Shiny.addCustomMessageHandler('showalert', function(message) {
          alert(message);
        });
   });
"),

Use inside server.R:
session$sendCustomMessage(type = "showalert", "error message here")
Reply all
Reply to author
Forward
0 new messages