Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Shiny JS events #168

Open
aoles opened this issue Jun 8, 2018 · 3 comments
Open

Add support for Shiny JS events #168

aoles opened this issue Jun 8, 2018 · 3 comments

Comments

@aoles
Copy link

aoles commented Jun 8, 2018

Hi Dean,
long time no see ;) I can't say that enough: your package is awesome! The only thing I'm currently missing is the support for Shiny events. Right now I'm implementing king of a busy indicator which can be easily set-up with a custom JS code as shown in the example. Yet, it would be really great if something along the following lines would be possible - what do you think?

Cheers,
Andrzej

library(shinyjs)

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    ...
    div(id = "loader")
    ),
  server = function(input, output) {
    ...
    onshiny("busy", show("loader"))
    onshiny("idle", hide("loader"))
  }
)
@daattali
Copy link
Owner

daattali commented Jun 8, 2018

That sounds like a good idea!

It would be similar to the onevent() function. The first argument would be the event to listen to, and the second argument could either be an expression or a callback function with a single argument. I don't have any time in the foreseeable future to work on this but I would gladly welcome a PR.

@daattali
Copy link
Owner

I started work on this in the feature-onshiny branch if anyone wants to continue. I don't know if I'll finish implementing this.

@ch0c0l8ra1n
Copy link

ch0c0l8ra1n commented May 26, 2024

@daattali Your approach on the feature-onshiny works for all shiny events except shiny:busy, shiny:idle. Any expression called on shiny:idle will inadvertently make shiny busy and trigger shiny:busy. There's an infinite recursion. Likewise any expression that's to be called on shiny:busy will not be evaluated until after shiny is idle.

These should be handled on js itself as that won't make shiny busy and can be executed even when shiny is busy.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants