Shiny bookmarks, automating clicks

Hey all,

We have a shiny at work that should definitely be an API.

It is used to generate a complex SQL query that creates a new table on the SQL server. Basically, you have buttons to select which time frame you want, which filters you want to apply, what variables you want to keep, etc. Then you click "go" and it generates that query and send it to the SQL server for processing.

Some people have to generate 20+ tables every month. They have to click 60+ variables for each tables because they want to keep 60 variables. Very time consuming, very error-prone.

The obvious fix would be to make it an API so that you can just make a cronjob that requests these tables every month. The team responsible for this won't do it

Is there a way to "automate" clicks in a shiny app? I've found you can do bookmarks in shiny (Chapter 11 Bookmarking | Mastering Shiny) , so at least we could pre-fill the filters, time frames and variables requested. But can we also automate clicking the "go" button ?

Assuming that your "go" button is an instance of actionButton(), you can use the click() function from the shinyjs library to trigger it programmatically.

1 Like

thanks for replying! shinyjs is new to me, so I'll definitely be falling down a rabbit hole today.

I have two needs:

  1. the app must still be usable in the current "manual" state, where someone connects to the shiny in firefox, does a few click then presses " go".

  2. I would like a power-user to be able to automatically do the same (maybe using shiny bookmarks?), by sending that query from R or a command line.

My understanding is that the "click()" function doesnt do what I need. It would involve added a line to the code of the shiny app so that it "clicks itself". The problem I see is that "click" would happen for all users, not just the "automated power user".

Is that correct?

edit: maybe I would just need to deploy 2 apps, one with the click() function and one without? kinda crazy, but might be less work than creating an API and making sure that any change in the shiny app are reflected in the api..

First off, using click() in no way impedes users clicking on the button the old fashioned way.

As far as "automated power user" v. "mere mortal user", the key would be how your code distinguishes between the two. You can embed in your code some routine that essentially does a sequence of steps / provides a sequence of inputs and then invokes the click() function. The issue would be how to give the power user access to that routine without giving all users access.

It might also be that you do not need to bother with click(). Let's say you write you code so that a user manually clicking the button triggers execution of some function. You can give the automated user a routine that, after doing whatever, calls the same function, producing the same result that a manual click would have produced.

thanks Paul, I don't understand everything yet as I need to do some digging, but I'm glad to know it's possible.
cheers

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.