Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to remove all theme and css style of tables #241

Open
dongweigogo opened this issue Apr 6, 2023 · 6 comments
Open

A way to remove all theme and css style of tables #241

dongweigogo opened this issue Apr 6, 2023 · 6 comments

Comments

@dongweigogo
Copy link

I am currently using huxtable for displaying some table and it is working good.
But I found that the css style is always added to huxtable object even when I use theme_basic(). Although the themes in huxtable are nice, I prefer my own ones.
Thus, I would like to know if there is a way to remove the buildin themes and css style. The raw HTML code is probably what I need.

@dongweigogo dongweigogo changed the title A way to remove all theme A way to remove all theme and css style of tables Apr 6, 2023
@hughjonesd
Copy link
Owner

Hmm, seems reasonable. I'll look into it.

@hughjonesd
Copy link
Owner

A workaround right now might be to capture the HTML with to_html and then edit it with tools from another package.

@hughjonesd
Copy link
Owner

Maybe an argument to to_html with a default options(huxtable.strip_css)would make sense, because probably people will want to do this for many tables in a document.

@hughjonesd
Copy link
Owner

Hmm. Let me check. Do you really mean all the CSS - heights, colours, everything?

If so, that will remove most of the functionality. So then I think the best thing would be a new function to_basic_html. But I might also think that this is beyond the package scope, and you'd do better to strip the CSS using a different tool.

@dongweigogo
Copy link
Author

t.
I agree that CSS matters a lot with functionality, actually the buildin css style changes the padding, background color, border width in my case. Any approach to that is OK with me. Thanks.

@hughjonesd
Copy link
Owner

So, I think the best way to do this is with xml2. Here is an example:

library(huxtable)
library(xml2)
jams
jams_tbl <- jams |> 
  huxtable::as_html() |>
  read_html() |>
  xml_find_first("./table")

xml_set_attr(jams_tbl, "class", "myclass") # modification in place, unusual for R 
tds <- xml_find_all(jams_tbl, ".//td")
xml_set_attr(tds, "style", "") # remove all styles

as.character(jams_tbl)

I'm still open to doing this if there is demand. There may also be better HTML manipulation libraries that I don't know about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants