Skip to content Skip to sidebar Skip to footer

Observe Sweetalert2 Confirm With Javascript In R Shiny

I have switched to sweetalert2 since the old version is more limited than the new version which is actively developped. I am running into a problem however, the code I used to obs

Solution 1:

Thanks to Stéphane Laurents comments, this is the solution: Including the means to send a variable back to R shiny.

myjava <- "shinyjs.swalFromButton = function(params) { 
var defaultParams = {
title : null,
html : null
};
params = shinyjs.getParams(params, defaultParams);
swal({title : params.title, html : params.html, 
showConfirmButton : true,
confirmButtonText : 'Left',
confirmButtonColor: '#00cc00',
showCancelButton : true,
cancelButtonText : 'Right',
cancelButtonColor :  '#339fff',
closeOnCancel : true,
allowOutsideClick: true,
allowEscapeKey: true,
closeOnConfirm: true})
.then(function(result){
  swal('succes');
  if (result.value === true) {
 var val1= true;
  Shiny.setInputValue('option1', val1, {priority: "event"});}  
else { 
swal('failure');
var val2= true;
          Shiny.setInputValue('option2', val2, {priority: "event"});}  
});
};"

Post a Comment for "Observe Sweetalert2 Confirm With Javascript In R Shiny"