Reputation: 985
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);")
Upvotes: 0
Views: 116
Reputation: 349956
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.
Upvotes: 1
Reputation: 33597
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);
`)
Upvotes: 0