Skip to content

Commit 1191824

Browse files
committed
Merge pull request rstudio#943 from yihui/feature/events-more
Events shiny:visualchange, shiny:conditional, and shiny:recalculating
2 parents 9041976 + 04e10a4 commit 1191824

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

R/shiny.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ ShinySession <- R6Class(
471471

472472
obs <- observe({
473473

474+
self$sendCustomMessage('recalculating', list(
475+
name = name, status = 'recalculating'
476+
))
477+
474478
value <- try(
475479
{
476480
tryCatch(
@@ -491,6 +495,10 @@ ShinySession <- R6Class(
491495
silent=FALSE
492496
)
493497

498+
self$sendCustomMessage('recalculating', list(
499+
name = name, status = 'recalculated'
500+
))
501+
494502
private$invalidatedOutputErrors$remove(name)
495503
private$invalidatedOutputValues$remove(name)
496504

inst/www/shared/shiny.js

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/init_shiny.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ function initShiny() {
253253
}
254254
});
255255
$('.shiny-bound-output').each(function() {
256-
$(this).data('shiny-output-binding').onResize();
256+
var $this = $(this), binding = $this.data('shiny-output-binding');
257+
$this.trigger({
258+
type: 'shiny:visualchange',
259+
visible: !isHidden(this),
260+
binding: binding
261+
});
262+
binding.onResize();
257263
});
258264
}
259265
var sendImageSizeDebouncer = new Debouncer(null, doSendImageSize, 0);
@@ -296,12 +302,19 @@ function initShiny() {
296302
$('.shiny-bound-output').each(function() {
297303
delete lastKnownVisibleOutputs[this.id];
298304
// Assume that the object is hidden when width and height are 0
299-
if (isHidden(this)) {
305+
var hidden = isHidden(this), evt = {
306+
type: 'shiny:visualchange',
307+
visible: !hidden
308+
};
309+
if (hidden) {
300310
inputs.setInput('.clientdata_output_' + this.id + '_hidden', true);
301311
} else {
302312
visibleOutputs[this.id] = true;
303313
inputs.setInput('.clientdata_output_' + this.id + '_hidden', false);
304314
}
315+
var $this = $(this);
316+
evt.binding = $this.data('shiny-output-binding');
317+
$this.trigger(evt);
305318
});
306319
// Anything left in lastKnownVisibleOutputs is orphaned
307320
for (var name in lastKnownVisibleOutputs) {

srcjs/shinyapp.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ var ShinyApp = function() {
283283
};
284284

285285
this.$updateConditionals = function() {
286+
$(document).trigger({
287+
type: 'shiny:conditional'
288+
});
289+
286290
var inputs = {};
287291

288292
// Input keys use "name:type" format; we don't want the user to
@@ -503,6 +507,16 @@ var ShinyApp = function() {
503507
}
504508
});
505509

510+
addCustomMessageHandler('recalculating', function(message) {
511+
if (message.hasOwnProperty('name') && message.hasOwnProperty('status')) {
512+
var binding = this.$bindings[name];
513+
$(binding ? binding.el : null).trigger({
514+
type: 'shiny:' + message.status
515+
});
516+
}
517+
});
518+
519+
506520
// Progress reporting ====================================================
507521

508522
var progressHandlers = {

0 commit comments

Comments
 (0)