posit-dev / posit-dev/py-shiny
Index issues with render.table and render.data_frame
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 135
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 21
Description
I ran into a bit of unexpected behaviour rendering data tables. When calculating group-wise statistics in pandas we don't include the grouping column by default in the rendered table unless the user sets index=True. There are two issues with this:
- The default for printing pandas tables includes the index, so we should follow that pattern
render.data_framedoesn't seem to have support for printing indexes, or at least follows a different API pattern
from shiny import App, render, ui, reactive
import pandas
import pandas as pd
data = {
"group": ["A", "A", "B", "B", "A", "B", "A", "B"],
"value1": [10, 20, 30, 40, 50, 60, 70, 80],
"value2": [5, 15, 25, 35, 45, 55, 65, 75],
}
df = pd.DataFrame(data)
means_by_group = (
df.set_index("group")
.groupby(level="group")
.agg({"value1": "mean", "value2": "mean"})
)
app_ui = ui.page_fluid(ui.output_table("table"), ui.output_data_frame("df"))
def server(input, output, session):
@output
@render.table(index=True)
def table():
return means_by_group
@output
@render.data_frame()
def df():
return means_by_group
app = App(app_ui, server)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the grouped pandas example and read the render.table(index=True) and render.data_frame entry points to compare their index APIs and defaults. Done means both renderers consistently expose the grouping/index column, with the intended default matching pandas table output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100