EDA on a server¶
This example shows how to inspect data and plots when working on a server or terminal-based environment.
The example publishes:
- a DataFrame
- a summary object
- a matplotlib plot
Install dependencies¶
or:
Create the script¶
Create eda_example.py:
eda_example.py
import matplotlib.pyplot as plt
import polars as pl
import plotsrv as ps
HOST = "127.0.0.1"
PORT = 8000
def main() -> None:
df = pl.DataFrame(
{
"month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
"bookings": [120, 150, 170, 160, 210, 240],
"returns": [115, 148, 165, 155, 205, 235],
}
)
summary = {
"rows": df.height,
"total_bookings": df["bookings"].sum(),
"total_returns": df["returns"].sum(),
"max_bookings": df["bookings"].max(),
"max_returns": df["returns"].max(),
}
fig, ax = plt.subplots()
ax.plot(df["month"], df["bookings"], marker="o", label="bookings")
ax.plot(df["month"], df["returns"], marker="o", label="returns")
ax.set_title("Bookings and returns")
ax.set_xlabel("Month")
ax.set_ylabel("Count")
ax.legend()
ps.publish_view(
df,
label="monthly data",
section="eda",
host=HOST,
port=PORT,
)
ps.publish_view(
summary,
label="summary",
section="eda",
host=HOST,
port=PORT,
)
ps.publish_view(
fig,
label="plot",
section="eda",
host=HOST,
port=PORT,
)
if __name__ == "__main__":
main()
Start plotsrv¶
In one terminal:
Open:
Run the script¶
In another terminal:
The UI should show:
- the source data as a table
- summary values as JSON
- the matplotlib plot as an image view
SSH workflow¶
For remote server work, use port forwarding from the local machine:
Then run plotsrv on the server:
Open locally:
This avoids exposing plotsrv directly to the network.
Attached version¶
For a quick local check, use launch_server=True instead of host and port:
Keep the process open at the end of the script:
What this example shows¶
plotsrv is useful when a script produces objects that are better inspected visually than printed:
- tables are easier to scan in a browser
- JSON summaries are easier to expand and inspect
- plots can be viewed on a headless server
- repeated script runs update the same UI