使用 shinny 删除 DT 包中的悬停选择
removing hover selection in DT package with shinny
我有一些小数据,我试图在闪亮的应用程序中显示一些自定义用户友好功能,如下载选项功能、查看 small/all 数据等。我的问题是如何删除悬停效果,因为我我正在使用颜色来突出显示某些值,当我 select 行时,悬停类型会删除颜色。任何人都可以帮我如何删除悬停 selection。下面是我 运行 的可重现代码...提前致谢。 enter image description here。注意代码不包含颜色部分
library(DT)
library(tidyverse)
library(formattable)
library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
table_options <- function() {
list(
dom = 'Bfrtip',
#Bfrtip
# pageLength = 10,
buttons = list(
c('copy', 'csv', 'excel', 'pdf', 'print'),
list(
extend = "collection",
text = 'Show All',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(-1);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)
)
),
deferRender = TRUE,
lengthMenu = list(c(-1,10,20), c('All', '10', '20')),
searching = TRUE,
#editable = TRUE,
scroller = TRUE,
lengthChange = FALSE
,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#517fb9', 'color': '#fff'});",
"}"
)
)
}
ui <- fluidPage(
titlePanel( h1("Iris data view", align = 'center'),
windowTitle = "Iris data "),
#theme = shinytheme("superhero"),
# Add the CSS
#tags$style(fmt_css),
# Create a container for tab panels
tabsetPanel(
# Create "Table" tab
tabPanel(
title = "Iris",
DT::dataTableOutput("table")
)
)
)
server <- function(input, output) {
# Creating a reactive variable named "filtered_data"
filtered_data <- reactive({
# Filter the data (copied from previous exercise)
data <- iris
data
})
output$table <- DT::renderDataTable({
data <- filtered_data()
DT::datatable(data,
rownames = FALSE,
#filter="top",
# editable = TRUE,
class = 'cell-border',
escape = FALSE,
#container = table_frame(),
options = table_options(),
extensions = 'Buttons'
)
})
}
shinyApp(ui, server)
您要查找的不是悬停,因为当鼠标悬停在行上时,这会改变行的颜色(这由 class
参数控制,class hover
包含在标准 display
class 中,因此这是默认行为 - 您已经更改了)。
我想你要找的是不允许行选择。这是由参数selection
控制的,你需要将它设置为none
:
library(DT)
library(shiny)
table_options <- function() {
list(
dom = 'Bfrtip',
#Bfrtip
# pageLength = 10,
buttons = list(
c('copy', 'csv', 'excel', 'pdf', 'print'),
list(
extend = "collection",
text = 'Show All',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(-1);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)
)
),
deferRender = TRUE,
lengthMenu = list(c(-1,10,20), c('All', '10', '20')),
searching = TRUE,
#editable = TRUE,
scroller = TRUE,
lengthChange = FALSE
,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#517fb9', 'color': '#fff'});",
"}"
)
)
}
ui <- fluidPage(
titlePanel( h1("Iris data view", align = 'center'),
windowTitle = "Iris data "),
#theme = shinytheme("superhero"),
# Add the CSS
#tags$style(fmt_css),
# Create a container for tab panels
tabsetPanel(
# Create "Table" tab
tabPanel(
title = "Iris",
DT::dataTableOutput("table")
)
)
)
server <- function(input, output) {
# Creating a reactive variable named "filtered_data"
filtered_data <- reactive({
# Filter the data (copied from previous exercise)
data <- iris
data
})
output$table <- DT::renderDataTable({
data <- filtered_data()
DT::datatable(data,
rownames = FALSE,
#filter="top",
# editable = TRUE,
class = 'cell-border',
escape = FALSE,
#container = table_frame(),
options = table_options(),
extensions = 'Buttons',
selection = "none"
)
})
}
shinyApp(ui, server)
我有一些小数据,我试图在闪亮的应用程序中显示一些自定义用户友好功能,如下载选项功能、查看 small/all 数据等。我的问题是如何删除悬停效果,因为我我正在使用颜色来突出显示某些值,当我 select 行时,悬停类型会删除颜色。任何人都可以帮我如何删除悬停 selection。下面是我 运行 的可重现代码...提前致谢。 enter image description here。注意代码不包含颜色部分
library(DT)
library(tidyverse)
library(formattable)
library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
table_options <- function() {
list(
dom = 'Bfrtip',
#Bfrtip
# pageLength = 10,
buttons = list(
c('copy', 'csv', 'excel', 'pdf', 'print'),
list(
extend = "collection",
text = 'Show All',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(-1);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)
)
),
deferRender = TRUE,
lengthMenu = list(c(-1,10,20), c('All', '10', '20')),
searching = TRUE,
#editable = TRUE,
scroller = TRUE,
lengthChange = FALSE
,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#517fb9', 'color': '#fff'});",
"}"
)
)
}
ui <- fluidPage(
titlePanel( h1("Iris data view", align = 'center'),
windowTitle = "Iris data "),
#theme = shinytheme("superhero"),
# Add the CSS
#tags$style(fmt_css),
# Create a container for tab panels
tabsetPanel(
# Create "Table" tab
tabPanel(
title = "Iris",
DT::dataTableOutput("table")
)
)
)
server <- function(input, output) {
# Creating a reactive variable named "filtered_data"
filtered_data <- reactive({
# Filter the data (copied from previous exercise)
data <- iris
data
})
output$table <- DT::renderDataTable({
data <- filtered_data()
DT::datatable(data,
rownames = FALSE,
#filter="top",
# editable = TRUE,
class = 'cell-border',
escape = FALSE,
#container = table_frame(),
options = table_options(),
extensions = 'Buttons'
)
})
}
shinyApp(ui, server)
您要查找的不是悬停,因为当鼠标悬停在行上时,这会改变行的颜色(这由 class
参数控制,class hover
包含在标准 display
class 中,因此这是默认行为 - 您已经更改了)。
我想你要找的是不允许行选择。这是由参数selection
控制的,你需要将它设置为none
:
library(DT)
library(shiny)
table_options <- function() {
list(
dom = 'Bfrtip',
#Bfrtip
# pageLength = 10,
buttons = list(
c('copy', 'csv', 'excel', 'pdf', 'print'),
list(
extend = "collection",
text = 'Show All',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(-1);
dt.ajax.reload();}"
)
),
list(
extend = "collection",
text = 'Show Less',
action = DT::JS(
"function ( e, dt, node, config ) {
dt.page.len(10);
dt.ajax.reload();}"
)
)
),
deferRender = TRUE,
lengthMenu = list(c(-1,10,20), c('All', '10', '20')),
searching = TRUE,
#editable = TRUE,
scroller = TRUE,
lengthChange = FALSE
,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#517fb9', 'color': '#fff'});",
"}"
)
)
}
ui <- fluidPage(
titlePanel( h1("Iris data view", align = 'center'),
windowTitle = "Iris data "),
#theme = shinytheme("superhero"),
# Add the CSS
#tags$style(fmt_css),
# Create a container for tab panels
tabsetPanel(
# Create "Table" tab
tabPanel(
title = "Iris",
DT::dataTableOutput("table")
)
)
)
server <- function(input, output) {
# Creating a reactive variable named "filtered_data"
filtered_data <- reactive({
# Filter the data (copied from previous exercise)
data <- iris
data
})
output$table <- DT::renderDataTable({
data <- filtered_data()
DT::datatable(data,
rownames = FALSE,
#filter="top",
# editable = TRUE,
class = 'cell-border',
escape = FALSE,
#container = table_frame(),
options = table_options(),
extensions = 'Buttons',
selection = "none"
)
})
}
shinyApp(ui, server)