【发布时间】:2020-02-01 08:20:36
【问题描述】:
我在 Shiny 中的 rhandsontable 渲染效果很好。除其他外,列'Pat。 Owes 和 Ins。 Owes 的显示格式为 US$(参见下面代码部分底部的第 4 行和第 5 行):
renderRHandsontable({
sessions_reactive$sessions[[patient_nr]],
row_highlight = row_highlight, col_highlight = col_highlight,
width = 1000, height = 500) %>%
hot_rows(fixedRowsTop = 1) %>%
hot_col("Pat. Owes", format = "$0,000.00", language = "en-US") %>%
hot_col("Ins. Owes", format = "$0,000.00", language = "en-US") %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_validate_numeric(cols = c(3, 5), min = 0, max = 500) %>%
hot_col(c(1, 3, 5, 6, 8), valign = 'htCenter')
})
下面的代码——但注释掉了这 2 条美元格式的行——也可以正常工作。底部的渲染器做了两件事:将第 5 列和第 8 列的字体设置为粗体和红色。此外,如果最后一列包含某个字符串,则整行的背景变为黄色。
rhandsontable(
sessions_reactive$sessions[[patient_nr]],
row_highlight = row_highlight, col_highlight = col_highlight,
width = 1000, height = 500) %>%
hot_rows(fixedRowsTop = 1) %>%
# hot_col("Pat. Owes", format = "$0,000.00", language = "en-US") %>%
# hot_col("Ins. Owes", format = "$0,000.00", language = "en-US") %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_validate_numeric(cols = c(3, 5), min = 0, max = 500) %>%
hot_col(c(1, 3, 5, 6, 8), valign = 'htCenter') %>%
hot_cols(renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (instance.params) {
hrows = instance.params.row_highlight
hrows = hrows instanceof Array ? hrows : [hrows]
hcols = instance.params.col_highlight
hcols = hcols instanceof Array ? hcols : [hcols]
if (hrows.includes(row)) {
td.style.background = 'yellow'
}
if (hcols.includes(col)) {
td.style.fontWeight = 'bold'
td.style.color = '#fc0f03'
}
}
}")
})
我的问题:如果我取消注释 2 条专门用于 US$ 格式的已注释 hot_col 行 - 它们不能与底部的渲染器结合使用。我的意思是,没有错误,但是这 2 列只是没有显示为 US$ 格式——它们只是显示为数字。显然,我在底部的渲染器(尽管它没有专门引用这些列)以某种方式否定了 US$ 格式。 将这两行移到 rhandsontable 定义的底部也无济于事。渲染的东西工作正常,但美元格式不工作。
有什么建议吗? 非常感谢!
【问题讨论】:
-
@Ben 嗨,Ben! :) 真的,rHandsontable 的作者不是在回答很多人的问题时告诉他们应该是文本渲染器吗?
-
是的,它做到了!惊人的!谢谢你,本!也许让您的评论成为答案,以便我接受?
标签: r rhandsontable