Shiny.setInputValue and Shiny JavaScript events

  • On the R side, we’ll access it with input$isMac.
  • This allows you to conditionally display elements
// 1. Wait for the shiny:connected event
$(document).on('shiny:connected', function(event) {
  
  // 2. Access to the Shiny JS object
  Shiny.setInputValue(
  
    // 3. Definine the id to use
    'isMac', 
    
    // 4. Confirm if the user has MacOS
    (navigator.appVersion.indexOf('Mac') != -1)
    
  );
  
});