由于用户选择,当列改变位置时,在Shiny中取消选择DT :: formatRound中的列

问题描述 投票:0回答:1

我正在制作一个闪亮的应用程序(https://joshmyers.shinyapps.io/WAINorms/)。第三个选项卡“规范数据”显示基于一些用户输入的数据表。我的输出代码是:

output$table = renderDataTable({
datatable(norms.df(), options = list(
lengthMenu = list(c(50, 100, 200, -1), c('50', '100', '200', 'All')), 
pageLength = 100), rownames = FALSE, class = 'white-space: nowrap stripe hover') 
%>% formatRound(columns = -c(1:2), digits =  2)
})

formatRound函数舍入所有列,除了前两个到两个小数位。问题是,这也围绕“百分位”列,我不想要。

问题是它根据“民族特定”的选择切换位置 - 如果“否”百分位数是第3列,但如果“是”它变为第4列,则插入另一列“种族”。

除了“Measure”,“Age”,“Percentile”和“Ethnicity”之外,我如何将所有列舍入到2位小数?

r datatable shiny dt
1个回答
0
投票

这不是我想要的,但我可以忍受它。你可以将formatRound函数链接在一起(https://rstudio.github.io/DT/functions.html),这样我就可以将'Percentile'列四舍五入到一个小数位,这是可以接受的。不过,我决定改用formatSignif

datatable(norms.df()) %>% 
formatSignif("Percentile", 3) %>% 
formatRound( -c(1:2), 2) 
© www.soinside.com 2019 - 2024. All rights reserved.