Skip to content

Commit

Permalink
Merge branch 'main' into improve_dark_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts authored Sep 7, 2024
2 parents de9be13 + 1f6f0a6 commit d36132e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![ITables logo](https://raw.githubusercontent.com/mwouts/itables/3f8e8bd75af7ad38a500518fcb4fbbc370ea6c4c/itables/logo/wide.svg)

![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
[![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/mwouts/itables/actions)
[![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
[![Pypi](https://img.shields.io/pypi/v/itables.svg)](https://pypi.python.org/pypi/itables)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/itables.svg)](https://anaconda.org/conda-forge/itables)
Expand Down
6 changes: 4 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
ITables ChangeLog
=================

2.1.5-dev (2024-07-??)
2.1.5-dev (2024-09-??)
------------------

**Added**
**Fixed**
- We have improved the function that determines whether a dark theme is being used ([#294](https://github.com/mwouts/itables/issues/294))
- We have adjusted the generation of the Polars sample dataframes to fix the CI ([Polars-18130](https://github.com/pola-rs/polars/issues/18130))
- The test on the Shiny app fallbacks to `ui.nav_panel` when `ui.nav` is not available


2.1.4 (2024-07-03)
Expand Down
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kernelspec:

![ITables Logo](../src/itables/logo/text.svg)

![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
[![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/mwouts/itables/actions)
[![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
[![Pypi](https://img.shields.io/pypi/v/itables.svg)](https://pypi.python.org/pypi/itables)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/itables.svg)](https://anaconda.org/conda-forge/itables)
Expand Down
33 changes: 22 additions & 11 deletions docs/streamlit.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# Streamlit

ITables in version `2.1.0` or above can be used in Streamlit.
To display Python DataFrames as interactive DataTables in Streamlit applications, use

To render a DataFrame with ITables in a Streamlit app, use `itables.streamlit.interactive_table`:
```
from itables.streamlit import interactive_table
```

The function `interactive_table` accepts the same arguments as `show` and `to_html_datatable`, e.g. the
first argument is the dataframe that will be displayed, and then you
can set a `caption`, custom `classes` or `style`, and even activate the `buttons` extension, etc...

## A sample application

A sample Streamlit application is available at [itables.streamlit.app](https://itables.streamlit.app) (source code [here](https://github.com/mwouts/demo_itables_in_streamlit/blob/main/itables_app.py))
We have a sample application available at https://itables.streamlit.app (source code [here](https://github.com/mwouts/demo_itables_in_streamlit/blob/main/itables_app.py))

```{div} full-width
<iframe src="https://itables.streamlit.app?embed=true"
style="height: 600px; width: 100%;"></iframe>
```

## Limitations of ITables in Streamlit
## Limitations

From a user perspective, you will be able to use `interactive_table` in a
In most cases, you will be able to use `interactive_table` in a
Streamlit application in the same way that you use `show` in notebooks.

Due to implementation constraints, the Streamlit component has some limitations
Expand All @@ -32,6 +27,22 @@ the Streamlit component needs to pass the table data to the frontend in JSON for
- JavaScript callbacks like custom formatting functions are not supported
- The interactive table is rendered within an iframe that has a fixed weight. This does not work well with the `lengthMenu` control, nor with the advanced filtering extensions (if that is an issue for you, please subscribe or contribute to [#275](https://github.com/mwouts/itables/issues/275)).

## Workaround

If you hit one of the limitations above, you can fallback to using `to_html_datatable` in combination with Streamlit's `html` function.

Please note that:
- you will have to specify the table height manually,
- an internet connection is required when using `to_html_datatable`,
- the app/table might take longer to display.

A sample application is available at https://to-html-datatable.streamlit.app (source code [here](https://github.com/mwouts/to_html_datatable_in_streamlit/blob/main/itables_app.py))

```{div} full-width
<iframe src="https://to-html-datatable.streamlit.app?embed=true"
style="height: 600px; width: 100%;"></iframe>
```

## Future developments

ITables' Streamlit component might see the following developments in the future
Expand Down
42 changes: 16 additions & 26 deletions packages/itables_for_streamlit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/itables/sample_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,15 @@ def get_dict_of_test_dfs(N=100, M=100, polars=False):
import pyarrow as pa

polars_dfs = {}
for key in test_dfs:
for key, df in test_dfs.items():
if key == "multiindex":
# Since Polars 1.2, pl.from_pandas fails with this error:
# ValueError: Pandas dataframe contains non-unique indices and/or column names.
# Polars dataframes require unique string names for columns.
# See https://github.com/pola-rs/polars/issues/18130
df.index = df.index.tolist()
try:
polars_dfs[key] = pl.from_pandas(test_dfs[key])
polars_dfs[key] = pl.from_pandas(df)
except (pa.ArrowInvalid, ValueError):
pass
return polars_dfs
Expand Down
2 changes: 1 addition & 1 deletion tests/sample_python_apps/itables_in_a_shiny_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Run this app with "shiny run file.py"
from shiny import App, ui

from itables.sample_dfs import get_countries
Expand All @@ -8,4 +9,3 @@
app_ui = ui.page_fluid(ui.HTML(DT(df)))

app = App(app_ui, server=None)
# app.run()
10 changes: 8 additions & 2 deletions tests/sample_python_apps/itables_in_a_shiny_app_with_tabs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Run this app with "shiny run file.py"
from shiny import App, ui

from itables.sample_dfs import get_dict_of_test_dfs
from itables.shiny import DT

try:
# This one is not available on the CI (Python 3.8)
ui_nav = ui.nav
except AttributeError:
ui_nav = ui.nav_panel

app_ui = ui.page_fluid(
# Display the different tables in different tabs
ui.navset_tab(
*[ui.nav(name, ui.HTML(DT(df))) for name, df in get_dict_of_test_dfs().items()]
*[ui_nav(name, ui.HTML(DT(df))) for name, df in get_dict_of_test_dfs().items()]
)
)

app = App(app_ui, server=None)
# app.run()
5 changes: 5 additions & 0 deletions tests/test_update_samples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from pathlib import Path

import pytest
import world_bank_data as wb

pytestmark = pytest.mark.xfail(
reason="HTTPError: 502 Server Error: Bad Gateway for url: http://api.worldbank.org/v2..."
)

SAMPLE_DIR = Path(__file__).parent / ".." / "src" / "itables" / "samples"


Expand Down

0 comments on commit d36132e

Please sign in to comment.