Exemplo n.º 1
0
def figure_to_vdom_image(figure):
    buf = io.BytesIO()
    figure.savefig(buf, format='png')
    buf.seek(0)
    string = base64.b64encode(buf.read())

    return vdomh.div(vdomh.img(src='data:image/png;base64,' +
                               urllib.parse.quote(string)),
                     style={"display": "inline-block"})
Exemplo n.º 2
0
def fig2vdom(fig, **kwargs):
    """Convert a matplotlib figure to an online image
    """
    buf = io.BytesIO()
    fig.savefig(buf, format='png', bbox_inches='tight')
    buf.seek(0)
    string = base64.b64encode(buf.read())
    plt.close()
    return img(src='data:image/png;base64,' + urllib.parse.quote(string),
               **kwargs)
Exemplo n.º 3
0
async def get_dashboard():
    example = div(
        span(img(src=image_url, style=dict(width='100', heigth='100')),
             h1('Smart 311 Dashboard')),
        p('Written in Python, 100%'),
        topten(),
        p('Top ten complaint types'),
    ).to_html()

    return HTMLResponse(content=example)
Exemplo n.º 4
0
def cache_fig(fig, output_dir, url_dir, k, width=840, cache=True):
    import plotnine
    output_file = os.path.join(output_dir, k + ".png")
    output_file_url = os.path.join(url_dir, k + ".png")
    if not (os.path.exists(output_file) and cache):
        if isinstance(fig, plotnine.ggplot):
            fig.save(output_file)
        else:
            fig.savefig(output_file)
    return img(src=output_file_url, width=width)
Exemplo n.º 5
0
def topten():
    fig, ax = plt.subplots()
    df['complaint_type'].value_counts().head(10).plot(kind='barh', ax=ax)
    plt.tight_layout()

    buf = io.BytesIO()
    fig.savefig(buf, format='png')
    buf.seek(0)

    string = base64.b64encode(buf.read())
    plt.close()

    return img(src='data:image/png;base64,' + urllib.parse.quote(string))
Exemplo n.º 6
0
def template_vdom_pattern(name,
                          n_seqlets,
                          trimmed_motif,
                          full_motif,
                          figures_url,
                          add_plots={},
                          metacluster=""):

    return details(
        summary(
            name,
            f": # seqlets: {n_seqlets}",
            # br(),
            trimmed_motif),  # ", rc: ",  motif_rc),
        details(
            summary("Aggregated profiles and contribution scores)"),
            img(src=figures_url + "/agg_profile_contribcores.png", width=840),
        ),
        details(
            summary("Aggregated hypothetical contribution scores)"),
            img(src=figures_url + "/agg_profile_hypcontribscores.png",
                width=840),
        ),
        details(
            summary("Sequence"),
            full_motif,
            br(),
            img(src=figures_url + "/heatmap_seq.png", width=840 // 2),
        ),
        details(
            summary("ChIP-nexus counts"),
            img(src=figures_url + "/profile_aggregated.png", width=840),
            img(src=figures_url + "/profile_heatmap.png", width=840),
        ),
        details(
            summary("Importance scores (profile)"),
            img(src=figures_url + "/contrib_profile.png", width=840),
        ),
        details(
            summary("Importance scores (counts)"),
            img(src=figures_url + "/contrib_counts.png", width=840),
        ),
        *[details(summary(k), *v) for k, v in add_plots.items()],
        id=metacluster + "/" + name)
Exemplo n.º 7
0
def dashboard():
    return div(
        span(img(src=image_url, style=dict(width='100', heigth='100')),
             h1('Smart 311 Dashboard')), img(width='400', src=barplot_url),
        p('Written in Python, 100%'))
Exemplo n.º 8
0
from IPython.display import display
from vdom.helpers import h1, p, img, div, b

display(
    div(
        h1('Our Incredibly Declarative Example'),
        p('Can you believe we wrote this ', b('in Python'), '?'),
        img(src="https://media.giphy.com/media/xUPGcguWZHRC2HyBRS/giphy.gif"),
        p('What will ', b('you'), ' create next?'),
    ))