In the Shiny script below, the javascript function returns the id of the relevant 'a' tag when the hyperlink is clicked. This javascript function however works for all links on the page. If I wanted to limit which links this function was called up on how would that be done?
For example, in the script below I would only want the function to execute when either of the first three links are clicked but not the last two.
ui <- fluidPage( tags$script(HTML( "$(document).ready(function(){ $('body').on('click', 'a', function(evt){ Shiny.setInputValue('clicked_text', evt.target.id); }); })" )), tags$a(href = "#", id = 1, "id is 1"), br(), tags$a(href = "#", id = 2, "id is 2"), br(), tags$a(href = "#", id = 3, "id is 3"), br(), tags$a(href = "#", id = 4, "id is 4, javascript function should be suppressed for this link"), br(), tags$a(href = "#", id = 5, "id is 5, javascript function should be suppressed for this link"), textOutput("clicked_text"), ) server <- function(input, output) { output$clicked_text <- eventReactive(input$clicked_text, { input$clicked_text }) } shinyApp(ui = ui, server = server)```
https://stackoverflow.com/questions/67362730/shiny-assign-javascript-function-to-individual-links May 03, 2021 at 10:05AM
没有评论:
发表评论