【发布时间】:2021-10-16 01:05:49
【问题描述】:
我正在尝试加载文件执行各种预处理步骤,包括对数据进行子集化。我在一个单一的反应函数中完成这一切,然后将各种格式化的数据帧分配给一个列表,以便从渲染函数中“导出”。我在显示表格时遇到的挑战 renderDT 只喜欢一个数据框对象,在我试图弄清楚如何为某些单元格着色之前,这是可以的。我发现的所有样式单元格示例都需要数据表对象而不是数据框。参见示例:https://rstudio.github.io/DT/010-style.html
我正在尝试根据以下规则为 C 列着色 [1,10] = 绿色、[11,19] = 黄色和 [20,25] = 红色。我很欣赏有关如何修改 renderDT 以允许单元格的任何建议。如果有办法改变表格内的字体大小,还有人吗?
require(readxl)
require(openxlsx)
mydata<-structure(list(A = c(2, 2, 2, 6, 7, 8, 6, 7, 8, 6, 7, 8, 1, 1,
1, 1, 2), B = c("A", "A", "N", "O", "L", "L", "O", "L", "L",
"O", "L", "L", "A", "N", "N", "N", "A"), C = c(1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 24)), class = "data.frame", row.names = c(NA,
-17L))
runApp(
list(
ui = fluidPage(
titlePanel("Import QUEST, Design, & Mitigation Lists"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose QUEST xlsx formatted file',
accept = c(".xlsx")
)),
mainPanel(
tabsetPanel(type = "tab",
tabPanel("Tab1", DTOutput('first')),
tabPanel("Tab2", DTOutput('second'))
)))),
server = function(input, output){
mydata1 <- reactive({
req(input$file1)
inFile <- input$file1
mydata<-read_excel(inFile$datapath, 1)
data1<-mydata[which(mydata<3),]
data2<-mydata[which(mydata>6),]
quest<-list(data1,data2)
quest })
output$first <- renderDT({as.data.frame(mydata1()[1])})
output$second <- renderDT({as.data.frame(mydata1()[2])})
}
))
shinyApp(ui, server)
【问题讨论】: