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

plots in gt tables disappear on send #58

Closed
GregSutcliffe opened this issue Jun 25, 2019 · 11 comments
Closed

plots in gt tables disappear on send #58

GregSutcliffe opened this issue Jun 25, 2019 · 11 comments

Comments

@GregSutcliffe
Copy link

I'm using this example to render ggplot sparklines in a gt table, and then trying to send that table via blastula.

The table renders fine in RStudio, as does an email object containing it, e.g:

email_text <-
  "
Here's the table

{as_raw_html(my_gt_table)}
"

email_object <-
  compose_email(
    body = email_text)

print(email_object)

The viewer pane will correctly show the sparklines. However, when I call smtp_send() with my GMail credentials, the resulting email does not display the plots - the column is blank.

I'm sure I'm just doing something stupid, any debugging tips?

@GregSutcliffe
Copy link
Author

Update, the HTML file I saved from the RStudio preview pane worked fine for me, but did not render for my colleague who I sent it to - so now I'm suspecting browser issues. Is there a good way of sending table/plot data with Blastula?

@rich-iannone
Copy link
Member

This is an issue where we need to build functionality for deploying images to some sort of CDN. We can do this manually right now with the add_imgur_image() but I think we'd want a more automatic solution than that. This issue (#46) has some ideas on this.

@rich-iannone
Copy link
Member

@GregSutcliffe Please have a look at a temporary workaround (which is to become a permanent solution) in #87.

@GregSutcliffe
Copy link
Author

GregSutcliffe commented Oct 30, 2019

Thanks @rich-iannone!

I've had a play with the new branch on Blastula, looks nice - I can confirm the simple example of sending a single plot works for me. Bravo :)

However, I'm unclear on how to apply this to GT with embedded images. I have a working GT table, ~20 rows, each with a sparkline plot in the last column, like this:

2019-10-30-112537_1863x511_scrot

That is saved as object events, so how would I embed this in the compose email call? If I use:

email_object <-
  compose_email(
    body = md(c(
      "Here's the table below:
      ",
      events,
      "Cheers"
    )),
    footer =
      "Email sent on {current_date_time}."
  )

Then all I get is a page of HTML in my email, rather than a table. If I instead use as_raw_html(events) in the above block, then I do get the table - but the images are gone.

Am I missing something? Or is the usecase for GT simply not ready for use yet (which would be fine, to be clear)?

@rich-iannone
Copy link
Member

Would you able able to provide all the code for this? I can test it out and see what the problem is. What happens if you don’t include the sparkline column?

@GregSutcliffe
Copy link
Author

GregSutcliffe commented Oct 30, 2019

@rich-iannone here you go - https://gist.github.com/GregSutcliffe/207297b94ee4abc95412bd9c6c5911e5

Given gt@master and blastula@remove-glue-inputs that should reproduce the problem, I think. Essentially, it's a table of new_events using summarised data from past_events to give context. I've added some intermediate output so you can see what to expect. Although I'm sure there's a better way to generate the sparklines ... ;)

@GregSutcliffe
Copy link
Author

What happens if you don’t include the sparkline column?

Forgot to answer this - sorry.

So I commented out lines 62:64 and added sparkline to cols_hide. I then re-tried all the email_objects in the Gist:

1 - still produces raw HTML
2 - renders fine, expected since it was only missing the sparkline images anyway
3 - still crashes

@rich-iannone
Copy link
Member

rich-iannone commented Oct 30, 2019

In the gt() statement, I used:

events <-
  new_events %>%
    left_join(past_events,by='name') %>%
    mutate(sparkline = plot %>% .[[1]] %>% ggplot_image(aspect_ratio = 2, height = 60)) %>%
    select(-plot) %>%
    gt() %>%
    fmt_markdown(columns = vars(sparkline)) %>%
    cols_label(
      sparkline = "RSVP history",
    ) %>%
    tab_options(
      table.width = pct(100)
    )

Which got me a table with a plot column. The next step is to use this:

email_object <-
  compose_email(
    body = md(events %>% as_raw_html(inline_css = TRUE)),
    footer = "Yay"
  )

To get the email. The problem seems to lie in gt's as_raw_html() function because it currently strips out the Base64-encoded image. I'll post an issue in the gt repo for this.

@GregSutcliffe
Copy link
Author

GregSutcliffe commented Oct 31, 2019

So to clarify, you're also seeing the problem in email_object? I still get a table without plots in the final column, even with your code for email_object (which I think is the same as my second example), so if you're getting plots we're different somehow. That's with your changes to the gt() call, which is much cleaner, thanks!

Assuming yes, then it looks like a case of waiting for that issue with as_raw_html() to be fixed. Thanks for your help so far!

@sunainakollu
Copy link

So to clarify, you're also seeing the problem in email_object? I still get a table without plots in the final column, even with your code for email_object (which I think is the same as my second example), so if you're getting plots we're different somehow. That's with your changes to the gt() call, which is much cleaner, thanks!

Assuming yes, then it looks like a case of waiting for that issue with as_raw_html() to be fixed. Thanks for your help so far!

Not sure if it helps you now. I had the same issue and the ggplots would not render in the gt table in the email. I used print() instead of as_raw_html() and it worked.

@skr5k
Copy link

skr5k commented Dec 29, 2021

hi,
i ran into the same exact issue. to me it rather seems that gt::as_raw_html() is not the culprit, my html code as returned by gt::as_raw_html() still renders well when I manually save the code as an html file and display it in my browser. the svg charts disappear though, when I use blastula::md() (still saving as separate html file). Trying to cheat blastula::compose_email() and sending the raw html into the body doesnt work though either, so something in blastula::compose_email() seems to remove/disable stuff in the process of process_markdown(body) I suspect...

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

4 participants