【发布时间】:2020-08-11 04:11:38
【问题描述】:
对于闪亮的应用程序,我想逐行浏览数据框并突出显示(粗体、颜色或类似)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)
【问题讨论】:
-
使用
DT可能更容易,因为突出显示行/列的功能已经到位。例如:rstudio.github.io/DT/010-style.html。如果你想得到一个“普通”的表格,没有分页、过滤、排序、搜索……,你可以使用options = list(dom = "t")。