Skip to content

Conversation

@juleswg23
Copy link
Collaborator

@juleswg23 juleswg23 commented Nov 10, 2025

WIP

This is a small example that should replicate the blastula demo.

import numpy as np
import pandas as pd
from plotnine import ggplot, aes, geom_boxplot
from nbmail.compose import (
    md,
    compose_email,
    block_plot,
    block_text,
    block_image,
    create_blocks,
)
from datetime import date

variety = np.repeat(["A", "B", "C", "D", "E", "F", "G"], 40)
treatment = np.tile(np.repeat(["high", "low"], 20), 7)
note = np.arange(1, 281) + np.random.choice(np.arange(1, 151), 280, replace=True)
data = pd.DataFrame({"variety": variety, "treatment": treatment, "note": note})

gg = ggplot(data, aes(x="variety", y="note", fill="treatment")) + geom_boxplot()

sender_name = "Jules"

intro_text = md("""
Hello,

I just wanted to let you know that the *plotnine* plot you wanted to see 
is right here, in this email:
""")

closing_text = block_text(
    f"""
Cheers,

{sender_name}
"""
)

email_body = create_blocks(
    intro_text,
    block_plot(gg, alt="Boxplot", width=600),
    block_image("newspapers.jpg", alt="Newspapers", width=600),
    closing_text,
)

email_with_plot = compose_email(body=email_body, footer=f"Sent on {date.today()}")
email_with_plot.subject = "Here's your boxplot"
email_with_plot

See it in the browser

email_with_plot.show_browser()

Or send it

from dotenv import load_dotenv
import os
from nbmail import send_email_with_gmail

load_dotenv()
username = os.getenv("POSIT_ADDRESS")
password = os.getenv("POSIT_APP_PASSWORD")

email_with_plot.recipients = [username]

send_email_with_gmail(username=username, password=password,i_email=email_with_plot,)

closes #19

nearly identical in an abstract sense to blastula, but content is wrapped in mjml tags instead of my own custom html template.
@github-actions
Copy link

github-actions bot commented Nov 10, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://posit-dev.github.io/email-for-data-science/pr-preview/pr-24/

Built to branch gh-pages at 2025-11-12 21:22 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@juleswg23 juleswg23 marked this pull request as draft November 10, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add email "authoring" module

2 participants