https://github.com/carlolepelaars/fh-plotly
Plotly in FastHTML
https://github.com/carlolepelaars/fh-plotly
fasthtml plotly visualization web web-application
Last synced: about 1 year ago
JSON representation
Plotly in FastHTML
- Host: GitHub
- URL: https://github.com/carlolepelaars/fh-plotly
- Owner: CarloLepelaars
- License: mit
- Created: 2024-08-04T19:27:09.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-11T17:54:55.000Z (about 1 year ago)
- Last Synced: 2025-03-29T00:33:23.739Z (about 1 year ago)
- Topics: fasthtml, plotly, visualization, web, web-application
- Language: Python
- Homepage:
- Size: 318 KB
- Stars: 21
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fh-plotly


[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
Use Plotly charts with [FastHTML](https://github.com/AnswerDotAI/fasthtml).
## Installation
```bash
pip install fh-plotly
```
Make sure to add the right headers to your FastHTML app:
```python
from fasthtml.common import fast_app
from fh_plotly import plotly_headers
app, rt = fast_app(hdrs=plotly_headers)
```
This ensures that the required javascript and css files are always loaded.
## Examples
Run `examples/test_app.py` to see some basic plots.
```bash
python examples/test_app.py
```
The gist of conversion to Plotly is the `plotly2fasthtml` function.
```python
from fh_plotly import plotly2fasthtml
def generate_line_chart():
df = pd.DataFrame({'y': [1, 2, 3, 2], 'x': [3, 1, 2, 4]})
fig = px.line(df, x='x', y='y')
return plotly2fasthtml(fig)
```
## Contributing
Feel free to open an issue or a pull request.
Make sure to do an editable install with dev dependencies when working on contributions.
```bash
pip install uv
uv sync
```
To run tests:
```bash
pytest -s
```
The goal is to keep `fh-plotly` lightweight and compatible with Python 3.10+.