Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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);")
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

You can insert variables into strings using template literals:

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('${dynamicId}').textContent);
  `)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!