像這樣的東西應該可以完成這項工作。請注意,我有色行2:4的目的,而不是1:4的更多的功能:
library(shiny)
library(DT)
ui <- basicPage(
mainPanel(DT::dataTableOutput('mytable'))
)
server <- function(input, output,session) {
output$mytable = DT::renderDataTable(
DT::datatable(mtcars, options = list(
pageLength = 25,
rowCallback = JS('function(row, data, index, rowId) {',
'console.log(rowId)','if(rowId >= 1 && rowId < 4) {',
'row.style.backgroundColor = "pink";','}','}')
)
)
)
}
runApp(list(ui = ui, server = server))
編輯:動態色彩行:在這裏我只是用sub
來取代範圍以色行
library(shiny)
library(DT)
fnc <- JS('function(row, data, index, rowId) {',
'console.log(rowId)','if(rowId >= ONE && rowId < TWO) {',
'row.style.backgroundColor = "pink";','}','}')
ui <- basicPage(
sliderInput("colorrows", "Which to color:",min = 0, max = 10, value = c(1,3)),
mainPanel(DT::dataTableOutput('mytable'))
)
server <- function(input, output,session) {
Coloring <- eventReactive(input$colorrows,{
fnc <- sub("ONE",input$colorrows[1],fnc)
fnc <- sub("TWO",input$colorrows[2],fnc)
fnc
})
output$mytable = DT::renderDataTable(
DT::datatable(mtcars, options = list(pageLength = 25,rowCallback = Coloring())
)
)
}
runApp(list(ui = ui, server = server))
謝謝你的回答,BU我有一個問題,行是用戶輸入是否可以傳遞給他們rollCallBack參數,如'if(rowId> = input $ fromRow && rowId
查看上面的編輯,讓我知道你是否有任何問題 –