RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
449 stars 78 forks source link

how to observe inputs from a dynamically produced dropdownBlock #136

Open D3SL opened 3 years ago

D3SL commented 3 years ago

Hello. First off as is github tradition thank you for the fantastic package, it's got a lot of great expansions to the original shinydashboard that add a lot to usability and QoL.

I'm having some trouble with one of the updates to dropdowns though. Right now I use renderMenu() to capture inputs and dynamically populate a dropdownMenu() I use as a log during my shift, with items like "#XXXX - Foo'd the bar". I want to switch to dropdownBlock() so those items become clickable inputs but I can't figure out the server side logic since the inputs are all dynamically created on the fly.

So far the closest I've gotten is giving all dropdown items a shared unique prefix like "dropdownfoo_", using javascript in UI.r to pass the name of any input triggered to Server.r as input$lastbutton, and then using observeEvent() with conditional logic to check if the input's name starts with "dropdownfoo".

This works, but it's laggy and triggers when it isn't supposed to. The input$last_button reactive chain seems to pick a specific item in the dropdownBlock() and get "stuck" on it. Anytime I trigger renderMenu() to re-render the dropdown by altering an existing item or adding a new one the app will react as if I clicked on the specific item it's stuck on.

Example: Say I have the following entries:

"#001 - foo"
"#002 - bar"
"#003- baz"

If I change entry 001 to say "foobar" that will be updated, but then the app will react as if I had clicked 003 immediately after. If I add a new entry ("004 - barbaz") then it will save the new entry and again immediately afterwards react as if I had clicked 003. This also seems to be triggered sometimes while I'm going other places in the app and other things are being rendered.