vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

allow customizing table-layout property in HTML? #305

Closed arbelt closed 2 months ago

arbelt commented 2 months ago

Hello, thanks for the great package!

I was wondering if there was a reason that table-layout: fixed needed to be hard-coded into HTML tables, or if it could be customized. I've been testing some wide tables, which end up being quite cramped, and it looks like simply setting table-layout: auto generally leads browsers to do the right thing (make it horizontally scrollable).

vincentarelbundock commented 2 months ago

I believe this is only added when the width argument is used, and that some use cases of width depend on that. Isn't that incorrect?

You can always modify the table with a regular expression using the finalize argument. I have not tried it, but it might look something like this:

library(tinytable)
iris[1:4, 1:2] |>
    tt(width = c(.2, .4)) |>
    style_tt(finalize = function(x) {
             x@table_string = sub("fixed", "auto", x@table_string)
    })
arbelt commented 2 months ago

Thanks, didn't know about finalize — such a useful escape hatch!

Yes, it was only being added when width was used; this may have partially been my not understanding the details of the width argument.

That said, I think it may be a more general use case: I was trying to set relative widths within the table (e.g., equal width numeric columns) but not necessarily have the table itself be sized relatively in order to accommodate small screen sizes.

In the end, I was able to achieve this by wrapping the whole thing an a div with a max-width, and using the finalize trick to switch the table-layout to auto.

Thanks so much for the quick reply, and for the well-thought out package!

vincentarelbundock commented 2 months ago

Good to hear!

I'm not sure if there's anything that should be actionable here, so I'll close the issue. However, this might be useful info for others, so I'll post a link to this thread on the FAQ page of the tinytable website.

Thanks for giving us background and the outline of a pretty simple solution!