Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

passing a variable to JS in shiny

Below is the sample action button with JS in it.This is hard coded. But actually,
the ‘small_ID’ below is very dynamic and will get changed. So how can i pass a variable inside document.getElementById ? Can anyone help?

actionButton("show1",class = "act_button", list(span(id = "m1", class="top left", "Model 1"), span(class="top right", Sys.time())),
                         onclick = "Shiny.setInputValue('btnid', document.getElementById('small_ID').textContent);")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could do this with paste:

actionButton(
    "show1",
    class = "act_button", 
    list(
        span(id = "m1", class="top left", "Model 1"), 
        span(class="top right", Sys.time())
    ),
    onclick = paste(
       "Shiny.setInputValue('btnid', document.getElementById('",
       small_ID,
       "').textContent);",
       sep=""
    )
)

…where small_ID should be your variable holding the id.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading