Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda