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.
library(shiny)
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) {
tags$a(
words[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)