Table

#| '!! shinylive warning !!': |
#|   shinylive does not work in self-contained HTML documents.
#|   Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [viewer]
#| viewerHeight: 350

import pandas as pd

from shiny import App, render, ui

df = pd.DataFrame(
    {
        "Model": ["Mazda RX4", "Datsun 710", "Merc 240D", "Fiat 128", "Volvo 142E"],
        "MPG": [21.0, 22.8, 24.4, 32.4, 21.4],
        "Cylinders": [6, 4, 4, 4, 4],
        "Horsepower": [110, 93, 62, 66, 109],
    }
)

app_ui = ui.page_fluid(
    ui.input_slider("rows", "Rows to display", min=1, max=5, value=3),
    ui.output_table("table"),
    class_="px-3 pt-3",
)

def server(input, output, session):
    @render.table
    def table():
        return df.head(input.rows())

app = App(app_ui, server)
import pandas as pd

from shiny.express import input, render, ui

df = pd.DataFrame(
    {
        "Model": ["Mazda RX4", "Datsun 710", "Merc 240D", "Fiat 128", "Volvo 142E"],
        "MPG": [21.0, 22.8, 24.4, 32.4, 21.4],
        "Cylinders": [6, 4, 4, 4, 4],
        "Horsepower": [110, 93, 62, 66, 109],
    }
)

ui.input_slider("rows", "Rows to display", min=1, max=5, value=3)

@render.table  
def table():
    return df.head(input.rows())
import pandas as pd

from shiny import App, render, ui

df = pd.DataFrame(
    {
        "Model": ["Mazda RX4", "Datsun 710", "Merc 240D", "Fiat 128", "Volvo 142E"],
        "MPG": [21.0, 22.8, 24.4, 32.4, 21.4],
        "Cylinders": [6, 4, 4, 4, 4],
        "Horsepower": [110, 93, 62, 66, 109],
    }
)

app_ui = ui.page_fluid(
    ui.input_slider("rows", "Rows to display", min=1, max=5, value=3),
    ui.output_table("table"),  
)

def server(input, output, session):
    @render.table  
    def table():
        return df.head(input.rows())

app = App(app_ui, server)
No matching items

Relevant Functions

  • ui.output_table
    ui.output_table(id, **kwargs)

  • @render.table
    render.table(_fn=None, *, index=False, classes='table shiny-table w-auto', border=0, **kwargs)

No matching items

Details

A table output renders a pandas DataFrame as a static HTML table. Unlike Data Grid and Data Table, the resulting table is not interactive — users cannot sort, filter, or select rows.

Prefer @render.data_frame for most tables. @render.table predates it and is kept for cases where you want the raw HTML a DataFrame (or a pandas Styler) produces — for example to apply pandas styling that the interactive grid does not support, or to render a small summary table with no interactive machinery.

To make reactive table output, follow three steps:

  1. Add ui.output_table() to the UI, passing it a unique id.

  2. Define a function in the server that returns a pandas DataFrame (or any object with a .to_html() method, such as a pandas Styler).

  3. Decorate the function with @render.table and give it the same name as the output id. Shiny matches the two by name.

Use the @render.table parameters to tweak the rendering: index=True includes the data frame’s index, classes controls the Bootstrap table classes applied to the output, and border sets the table’s border attribute. Any further keyword arguments are passed through to the object’s .to_html() method.

For an interactive table, use Data Grid or Data Table instead.