html - 迭代地突出显示闪亮的渲染表中的一行
问题描述
对于闪亮的应用程序,我想逐行浏览数据框并突出显示(粗体、颜色或类似)中的选定行renderTable
。我正在考虑按索引选择行。我可以这样做renderTable
,还是应该考虑DT
?
library(shiny)
ui <-
fluidRow(
actionButton(
"my_button",
"Go to next row"
),
tableOutput("my_table")
)
server <- function(input, output){
values <- reactiveValues()
values$index <- 1
values$dat <- iris
observeEvent(
input$my_button, {
values$index <- values$index + 1
})
output$my_table <-
renderTable(values$dat) # somehow highlight the row at the index
}
shinyApp(ui = ui, server = server)
解决方案
这可能会让你开始。
library(shiny)
library(DT)
library(dplyr)
ui <-
fluidRow(
actionButton(
"my_button",
"Go to next row"
),
dataTableOutput("my_table")
)
server <- function(input, output){
values <- reactiveValues()
values$index <- 1
values$dat <- iris
observeEvent(
input$my_button, {
values$index <- values$index + 1
})
output$my_table <-
renderDataTable({
values$dat %>%
mutate(row = row_number()) %>%
datatable() %>%
formatStyle(
"row",
target = 'row',
backgroundColor = styleEqual(values$index, c('yellow'))
)
}) # somehow highlight the row at the index
}
shinyApp(ui = ui, server = server)
推荐阅读
- asp.net-core - 如何使用 .net 核心中的依赖注入来处理与 dapper 的 postgresql db 连接?
- angular - 在 cytoscape 的边缘标签中通过其 unicode 使用字体真棒图标不起作用
- postgresql - PostgreSQL 在选择和不同条件的表中插入值
- php - PHP 应用程序在最新版本的 IIS10 和 windows server 2019 上损坏
- docker - 我可以在 Docker-Compose 中提及 Docker 停止命令吗
- java - 如何向 stringbuilder 添加另一个字符串?
- qt - 单击按钮后,如何将不同变量的值添加到列表中?
- javascript - 为什么谷歌地图没有出现
- apache-spark - pyspark 代码在控制台中工作,但不在 zeppelin 中
- http - 使用 HTTPRoundTripper 重试