我想在 DT 的单元格 ID 中应用 JS/Jquery。
我用了.css()
作为例子,但是我有其他的计划,所以我提出了这个问题。我的意图不是给文字上色,而是使用其他功能。
我的代码:
library(shiny)
library(shinydashboard)
library(DT)
header <- dashboardHeader(title = "DT")
sidebar <- dashboardSidebar(sidebarMenu(menuItem(text = "mydatatable", tabName = "dt1")))
body <- dashboardBody(
HTML(
"<head>
<script>
$(function() {
$('#stackid, #dtid').mouseover(function() {
$(this).css('color','red');
});
$('#stackid, #dtid').mouseout(function() {
$(this).css('color','#333333');
});
});
</script>
</head>"
),
tabItems(
tabItem(
tabName = "dt1",
fluidPage(
column(
width = 12,
HTML("<strong id='dtid' style='font-size:50px;'>DATATABLE</strong>"),
DTOutput(outputId = "outdt1")
)
)
)
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output, session) {
df_1 <- data.frame(
x = c("<span id='stackid'>Stack</span>", "Over", "Flow"),
y = 1:3,
z = LETTERS[1:3]
)
output$outdt1 <- DT::renderDataTable({
datatable(
data = df_1,
escape = FALSE
)
})
}
shinyApp(ui, server)
我尝试在 JS/ jQuery
上使用 tags$div()
inside server
,但这也没有用。
看到效果如预期一样应用于 dtid
。但是,我的意图是在 DT
.