如果您想对任意HTML文件执行此操作,则可能无法使用,但这是一个纯R解决方案。使用javascript解决方案可能会更好:
library(shiny)
library(DT)
ui <- shinyUI(fluidPage(mainPanel(
DT::dataTableOutput("test"),
htmlOutput("html")
)))
server <- shinyServer(function(input, output, session) {
words <- data.frame(stringsAsFactors = FALSE,
words = c("the", "hello", "world"))
output$test <- DT::renderDataTable({
words
}, selection = list(mode = "single", target = "row"))
text <- "This is the hello world example for this problem."
output$html <- renderUI({
if (is.null(input$test_rows_selected))
return(HTML(text))
HTML(gsub(
words$words[input$test_rows_selected],
paste0("<mark>",
words$words[input$test_rows_selected],
"</mark>"),text ))
})
})
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
731 次 |
| 最近记录: |