Download server.py from Wanxai/Shiny-App: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/Wanxai/Shiny-App/resolve/main/server.py
- Command line
-
hf download hf://spaces/Wanxai/Shiny-App/server.py
-
curl -L -o server.py https://huggingface.co/spaces/Wanxai/Shiny-App/resolve/main/server.py
1.47 kB
| from shiny import render, reactive, ui | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| def create_server(): | |
| def server(input, output, session): | |
| # Update dropdowns when file is uploaded | |
| def _(): | |
| file = input.file() | |
| if file is not None: | |
| # Read the uploaded file | |
| df = pd.read_csv(file[0]['datapath']) | |
| choices = list(df.columns) | |
| ui.update_select("var1", choices=choices, session=session) | |
| ui.update_select("var2", choices=choices, session=session) | |
| # Render the data table | |
| def table(): | |
| file = input.file() | |
| if file is None: | |
| return None | |
| return pd.read_csv(file[0]['datapath']) | |
| # Render the plot | |
| def plot(): | |
| file = input.file() | |
| if file is None: | |
| return None | |
| df = pd.read_csv(file[0]['datapath']) | |
| # Create matplotlib scatter plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.scatter(df[input.var1()], df[input.var2()]) | |
| plt.xlabel(input.var1()) | |
| plt.ylabel(input.var2()) | |
| plt.title(input.plot_title()) | |
| return plt.gcf() | |
| return server |