Shiny click on text


My q is that is there any solution to make an input from a click on text. My target would be to show a text to the user and allow to highlight a given word. The application would save the position of the click.

Any idea or suggestion how to find this?

Thanks in advance

You could use links (HTML <a> Tag):


words <- unlist(strsplit(c(
  "R is free software and comes with ABSOLUTELY NO WARRANTY.",
  "You are welcome to redistribute it under certain conditions.",
  "Type 'license()' or 'licence()' for distribution details."),
  " "))

ui <- fluidPage(
  lapply(seq_along(words), function(i) {
    style = "color:black;",
    onclick = sprintf("Shiny.setInputValue(id = 'last_index_clicked', value = %s, {priority: 'event'});", i)
tagAppendAttributes(textOutput("last_word_clicked"), style = "margin-top:25px;"))

server <- function(input, output, session) {
  output$last_word_clicked <- renderText({
    sprintf("You clicked word %s: %s", input$last_index_clicked, words[input$last_index_clicked])

shinyApp(ui, server)


1 Like

You are amazing! Thank you :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.