Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="table" class="shiny-html-output shiny-bound-output"></div>
<button>render shiny simulation</button>

              
            
!

CSS

              
                /* copy from shiny */
.recalculating {
    opacity: 0.3;
    transition: opacity 250ms ease 500ms;
    -moz-transition: opacity 250ms ease 500ms;
    -webkit-transition: opacity 250ms ease 500ms;
    -o-transition: opacity 250ms ease 500ms;
}
              
            
!

JS

              
                jQuery(function($) {
// ---------------------------------------------------------------------------
// :: execute callback function when shiny output element is modified
// :: the callback can be called multiple times if you use option onTime: false
// :: you can also use check option with function that will be check if
// :: before executing callback and removing observer
// ::
// :: Copyright (C) Jakub T. Jankiewicz <https://jcubic.pl>
// :: Relased under MIT License
// ---------------------------------------------------------------------------
$.fn.onRender = function(callback, options) {
  var settings = $.extend({
    // if set to true will remove mutation observer after first mutation
    oneTime: true,
    // if set to true will always execute and clear mutation observer on first mutation
    // default will not fire callback when mution is recalcuation of any element
    strict: false,
    name: 'default',
    observer: {childList: true, subtree: true, attributes: true},
    check: function(node) { return node.closest('body').length; }
  }, options || {});
  var name = settings.name;
  if (arguments[0] == 'cancel') {
    return this.each(function() {
      var self = $(this);
      var render = self.data(name);
      if (render) {
        render.observer.disconnect();
        self.removeData(name);
      }
    });
  } else {
    return this.each(function() {
      var node = $(this);
      var render = node.data(name);
      if (!render) {
        render = {
          callbacks: $.Callbacks(),
          observer: new MutationObserver(function(mutations) {
            mutations = mutations.filter(function(mutation) {
              return mutation.type == 'attributes' &&
                     mutation.attributeName == 'class' ||
                     mutation.type != 'attributes';
            });

            // if recalculating wait for next mutation
            if (mutations.length &&
                (!(node.hasClass('recalculating') ||
                   node.find('.recalculating').length) ||
                 settings.strict)) {
                  if (settings.check(node)) {
                    render.callbacks.fireWith(node[0]);
                    if (settings.oneTime) {
                      node.onRender('cancel', settings);
                    }
                  }
            }
          })
        };
        render.observer.observe(node[0], settings.observer);
        node.data(name, render);
      }
      render.callbacks.add(callback);
    });
  }
};

// table copied from dev tools of demo shiny app
var table = `<table class="table shiny-table table- spacing-s" style="width:auto;">
    <thead> <tr> <th style="text-align: right;"> v1 </th> <th style="text-align: left;"> v2 </th> <th style="text-align: left;"> v3 </th>  </tr> </thead> <tbody>
    <tr> <td align="right"> 1.00 </td> <td> a </td> <td> TRUE </td> </tr>
    <tr> <td align="right"> 2.00 </td> <td> b </td> <td> TRUE </td> </tr>
    <tr> <td align="right" class="NA"> NA </td> <td> c </td> <td> FALSE </td> </tr>
    <tr> <td align="right"> 9.00 </td> <td> d </td> <td class="NA"> NA </td> </tr>
    <tr> <td align="right" class="NA"> NA </td> <td> e </td> <td> FALSE </td> </tr>
    <tr> <td align="right"> 7.00 </td> <td class="NA"> NA </td> <td> TRUE </td> </tr>
    </tbody> </table>`;

// this code runs once and it's running each time table is updated
$('#table').onRender(function() {
    $(this).find('table').tablesorter({
        theme: 'blue'
    });
}, {
    oneTime: false
});

// simulate shiny table update
$('button').click(function() {
    var $table = $('#table').addClass('recalculating');
    setTimeout(function() {
        $table.html(table).removeClass('recalculating')
    }, 2000);
}).click();
    
    
});


              
            
!
999px

Console