Created
November 12, 2022 17:29
-
-
Save AnnMarieW/537a78f9d3865b0fdf7e5d685e4f8f56 to your computer and use it in GitHub Desktop.
DataTable with icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
See other MWEs for images and text icons here: https://github.com/plotly/dash-table/pull/916 | |
Css in assets folder: (not tested yet maybe move the body font-size somewhere else since it will affect the entire app like this) | |
.cell-markdown > p { | |
display: flex; | |
height: 100%; | |
justify-content: center; | |
align-items: center; | |
} | |
body { | |
font-size: 15pt; | |
} | |
""" | |
from dash import Dash, html, dash_table | |
import pandas as pd | |
FONT_AWESOME = "https://use.fontawesome.com/releases/v5.10.2/css/all.css" | |
clouds = '<i class="fa fa-cloud" style="color: grey;"></i>' | |
rain = '<i class="fa fa-cloud-rain"></i>' | |
sun = '<i class="fa fa-sun" style="color: gold;"></i>' | |
app = Dash(__name__, external_stylesheets=[FONT_AWESOME]) | |
df = pd.DataFrame( | |
dict( | |
[ | |
("temperature", [13, 43, 50]), | |
("city", ["NYC", "Paris", "Seattle"]), | |
("icon", [sun, clouds, rain]), | |
] | |
) | |
) | |
app.layout = html.Div( | |
[ | |
dash_table.DataTable( | |
css=[dict(selector="p", rule="margin: 0px;")], | |
data=df.to_dict("records"), | |
columns=[ | |
{"id": "city", "name": "City"}, | |
{"id": "temperature", "name": "Temperature"}, | |
{"id": "icon", "name": "", "presentation": "markdown"}, | |
], | |
markdown_options={"html": True}, | |
style_table={"width": 200}, | |
) | |
] | |
) | |
if __name__ == "__main__": | |
app.run_server(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment