如何使用 rhansontable 和复选框更改某些行的颜色?
How to change the colour of some rows with rhansontable and checkbox?
我想在用户取消选中其中一个单元格中的复选框时更改整行的颜色。 (可以是多行)
到目前为止,我只能更改包含复选框的单元格的颜色,而不是整行。在这个例子中,整行 6
应该是彩色的。
library(shiny)
library(rhandsontable)
# Define UI for application that draws a histogram
ui <- fluidPage(
rHandsontableOutput('table')
)
# Define server logic required to draw a histogram
server <- function(input, output) {
df <- data.frame(alphabet = letters[1:10],
include = TRUE)
output$table <- rhandsontable::renderRHandsontable({
rhandsontable(df, height = 500) %>%
hot_col(col = "include",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
")
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决了。
library(shiny)
library(rhandsontable)
# Define UI for application that draws a histogram
ui <- fluidPage(
rHandsontableOutput('table')
)
# Define server logic required to draw a histogram
server <- function(input, output) {
df <- data.frame(alphabet = letters[1:10],
include = TRUE)
output$table <- rhandsontable::renderRHandsontable({
rhandsontable(df, height = 500) %>%
hot_col(col = "include",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
") %>%
hot_col(col = "alphabet",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
")
})
}
我想在用户取消选中其中一个单元格中的复选框时更改整行的颜色。 (可以是多行)
到目前为止,我只能更改包含复选框的单元格的颜色,而不是整行。在这个例子中,整行 6
应该是彩色的。
library(shiny)
library(rhandsontable)
# Define UI for application that draws a histogram
ui <- fluidPage(
rHandsontableOutput('table')
)
# Define server logic required to draw a histogram
server <- function(input, output) {
df <- data.frame(alphabet = letters[1:10],
include = TRUE)
output$table <- rhandsontable::renderRHandsontable({
rhandsontable(df, height = 500) %>%
hot_col(col = "include",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
")
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决了。
library(shiny)
library(rhandsontable)
# Define UI for application that draws a histogram
ui <- fluidPage(
rHandsontableOutput('table')
)
# Define server logic required to draw a histogram
server <- function(input, output) {
df <- data.frame(alphabet = letters[1:10],
include = TRUE)
output$table <- rhandsontable::renderRHandsontable({
rhandsontable(df, height = 500) %>%
hot_col(col = "include",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
") %>%
hot_col(col = "alphabet",
renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
var col_value = instance.getData()[row][1]
if (col_value === false) {
td.style.background = 'pink';
}
}
")
})
}