简体   繁体   中英

How to fix a table's column width on R Shiny using Formattable?

I would like to display the data frame on R Shiny using formattable. However, the solution here doesn't work. 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))

How can I do it? Thanks

Other than the DT solution, as said in the vignette of formattable, you can use elements from formattable with knitr::kable . Then you can use kableExtra to deal with the column width issue.

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

how to use it in Shiny: http://haozhu233.github.io/kableExtra/use_kable_in_shiny.html

General vignette: http://haozhu233.github.io/kableExtra/awesome_table_in_html.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM