【问题标题】:How to fix a table's column width on R Shiny using Formattable?如何使用 Formattable 在 R Shiny 上修复表格的列宽?
【发布时间】:2017-10-27 01:20:26
【问题描述】:

我想使用 formattable 在 R Shiny 上显示数据框。但是,这里的解决方案不起作用。 https://cran.r-project.org/web/packages/formattable/vignettes/formattable-data-frame.html

scores <- data.frame(id = 1:5,
                    prev_score = c(10, 8, 6, 8, 8),
                     cur_score = c(8, 9, 7, 8, 9),
                     change = c(-2, 1, 1, 0, 1))

width_formatter <- formatter("span",
                               style = x ~ style("width" = '100px'))


formattable(scores, list(width_formatter))

我该怎么做?谢谢

【问题讨论】:

  • 你可以用DT做同样的事情吗?

标签: r shiny formattable


【解决方案1】:

除了 DT 解决方案,如 formattable 的小插曲中所述,您可以使用 formattableknitr::kable 中的元素。然后你可以使用 kableExtra 来处理列宽问题。

http://haozhu233.github.io/kableExtra/use_kableExtra_with_formattable.html

如何在 Shiny 中使用它: http://haozhu233.github.io/kableExtra/use_kable_in_shiny.html

一般小插曲: http://haozhu233.github.io/kableExtra/awesome_table_in_html.html

【讨论】:

  • 这是一个非常好的软件包,谢谢。但是, column_spec(3, width = "30em") 函数似乎在 R Shiny 环境中不起作用。我尝试更改列的背景颜色,它可以工作。不知道为什么宽度函数没有。
  • @v_loves_avocados 你尝试在kable_styling 中设置full_width = F 吗?如果它不起作用,你能分享一个可重现的例子吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-05
  • 2019-08-08
  • 1970-01-01
  • 2016-01-02
相关资源
最近更新 更多