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

Exporting Ipydatagrid to html #486

Open
jobinnthomas opened this issue Mar 1, 2024 · 0 comments
Open

Exporting Ipydatagrid to html #486

jobinnthomas opened this issue Mar 1, 2024 · 0 comments

Comments

@jobinnthomas
Copy link

jobinnthomas commented Mar 1, 2024

Is there a way to export an ipydatagrid to html? I saw the code below...but the index.html it produced had blank values. I removed the renderers in code below and expected to see integer values but there were none
I am using ipydatagrid 1.6.0 and ipywidgets 8.1.2

I did find this as an old issue....#279 but I wanted to know if there are other ways to do it also...


import pandas as pd
import numpy as np
import json

from ipydatagrid import DataGrid, TextRenderer, Expr
n = 50_000
df = pd.DataFrame(
    {
        "Value 1": np.random.randn(n),
        "Value 2": np.random.randn(n),
        "Value 3": np.random.choice([True, False], n),
        "Value 4": np.random.choice([True, False], n),
    }
)

# This returns the unicode value for specific font-awesome icons,
# check-out this link for more icons:
# https://fontawesome.com/v4.7.0/cheatsheet/
def bool_render_text1(cell):
    if cell.value > 0:
        return "\uf00c"  # Check
    else:
        return "\uf00d"  # Cross

def bool_render_text2(cell):
    if cell.value > 0:
        return "\uf111"  # Circle
    else:
        return " "

def bool_render_text3(cell):
    if cell.value:
        return "\uf164"  # Thumb up
    else:
        return "\uf165"  # Thumb down

def bool_render_text4(cell):
    if cell.value:
        return "\uf118"  # Smile
    else:
        return "\uf119"  # Frown

def bool_render_color(cell):
    if cell.value > 0:
        return "#2fbd34"
    else:
        return "#b82538"

common_args = {
    "font": "bold 14px fontawesome",
    "text_color": Expr(bool_render_color),
    "horizontal_alignment": "center",
}
renderers = {
    "Value 1": TextRenderer(text_value=Expr(bool_render_text1), **common_args),
    "Value 2": TextRenderer(text_value=Expr(bool_render_text2), **common_args),
    "Value 3": TextRenderer(text_value=Expr(bool_render_text3), **common_args),
    "Value 4": TextRenderer(text_value=Expr(bool_render_text4), **common_args),
}
#display(df)
w = DataGrid(df, base_row_size=30, base_column_size=150)
display(w)
from ipywidgets.embed import embed_minimal_html
embed_minimal_html("index.html", w)
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

No branches or pull requests

1 participant