小编Lia*_*ang的帖子

R Shiny DataTable如何防止包含超链接的列中的行选择/取消选择

我正在处理一个带有可点击元素的数据表.该行的一列包含一个超链接.单击超级林时,我不希望触发或管理行点击事件(选择/取消选择).

我在R Shiny上尝试了什么:

function preventDefault(e) {
   e.preventDefault();
   e.stopPropagation();

   return false;
}
Run Code Online (Sandbox Code Playgroud)

DataTable中包含链接的元素:

<a href="#" onclick="preventDefault(event)";>
Run Code Online (Sandbox Code Playgroud)

但什么都没发生.

完整源代码:

library(shiny)
library(DT)
library(dplyr)

ui <- fluidPage(

   # Application title
  DT::dataTableOutput("DTExample")


)

server <- function(input, output) {
  dat <- head(iris)

  dat <- dat %>% mutate(clickme = '<a href="#" 
                     onclick="event.preventDefault(); event.stopPropagation(); alert(event); return false;";
                     >CLICKME</a>')

  output$DTExample<- renderDataTable({
    datatable(dat, escape = FALSE, class = 'cell-border stripe')
  }) 
}

# Run the application 
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

datatable r shiny

6
推荐指数
1
解决办法
718
查看次数

标签 统计

datatable ×1

r ×1

shiny ×1