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

Images in table cells #383

Open
prokulski opened this issue May 17, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@prokulski
Copy link

commented May 17, 2019

It is possible to add rendering images in cell? For example I put in cell string like "" and in table I get this image.

Workaround for Latex is here https://stackoverflow.com/questions/38555040/alignment-of-images-in-tables-with-markdown-rstudio-and-knitr but it won't work if you'll import knitr and then kableExtra. Without kableExtra it is difficult to change column width etc.

@ridwan-shaikh

This comment has been minimized.

Copy link

commented Jun 19, 2019

Hi Prokulski,

I am not sure if this answers your question but I have achieved this by pre-rendering the image, then adding a new column for the image eg:

table1 %>%
mutate(images = paste0("<","img src=","image_file_name",".png",">")) %>%
kable(format = "html", escape = F) %>%
kable_styling(bootstrap_options = "striped")

If you want specific images for specific rows, it possible by saving the image as the row number eg: 1.png and then having the image_file_name as nrow(table1):

table1 %>%
mutate(images = paste0("<","img src=",nrow(table1),".png",">")) %>%
kable(format = "html", escape = F) %>%
kable_styling(bootstrap_options = "striped")

If it is a static image that does not need to change, you can always:

gsub(pattern = "",
x = table1$column1,
replacement = paste0("<","img src=","image_file_name",".png",">"))

to replace all instances of "" with the image file name and when you render the table ensure you have format as "html" and escape = F.

@prokulski

This comment has been minimized.

Copy link
Author

commented Jun 19, 2019

I used the same trick, but it won't work when you want to render to pdf...

@ridwan-shaikh

This comment has been minimized.

Copy link

commented Jun 19, 2019

Never tried with a PDF because most tables lose that better html look. Could you render to html then use chrome_print from the pagedown package to convert the html to pdf document?

@prokulski

This comment has been minimized.

Copy link
Author

commented Jun 19, 2019

I do a lot of reports in PDFs (generated via Shiny app, by scripts runned in cron etc) so printing them manual isn't a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.