Download app.py from juhPark/mlpc: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/spaces/juhPark/mlpc/resolve/main/app.py
- Command line
-
hf download hf://spaces/juhPark/mlpc/app.py
-
curl -L -o app.py https://huggingface.co/spaces/juhPark/mlpc/resolve/main/app.py
2.95 kB
| import pandas as pd | |
| from pathlib import Path | |
| import plotly.express as px | |
| from shiny import App, Inputs, Outputs, Session, reactive, render, ui | |
| from shinywidgets import render_plotly, output_widget | |
| # Load your combined DataFrame | |
| combined_df = pd.read_csv("combined_df.csv", encoding="cp949") | |
| # Get the list of columns for dropdown options, excluding 'index' and 'sensor' | |
| columns = [col for col in combined_df.columns if col not in ["sensor"]] | |
| # Get the unique sensor values for the dropdown | |
| sensor_options = list(combined_df["sensor"].unique()) | |
| # Define the UI | |
| app_ui = ui.page_fluid( | |
| ui.h1("My Interactive Dashboard"), | |
| ui.layout_sidebar( | |
| ui.sidebar( | |
| ui.input_selectize( | |
| "sensor_dropdown", | |
| "Select sensors", | |
| choices=sensor_options, | |
| multiple=True, | |
| selected=sensor_options[0], | |
| ), | |
| ui.input_select( | |
| "x_axis_dropdown", "Select X-axis", choices=columns, selected="인덱스" | |
| ), | |
| ui.input_select( | |
| "y_axis_dropdown", | |
| "Select Y-axis", | |
| choices=columns, | |
| selected="PM1.0(㎍/㎥)", | |
| ), | |
| ui.input_radio_buttons( | |
| "graph_type_radio", | |
| "Graph type", | |
| choices={"line": "Line", "scatter": "Scatter"}, | |
| selected="line", | |
| ), | |
| ), | |
| output_widget("interactive_plot"), | |
| ), | |
| ) | |
| # Define the server logic | |
| def server(input: Inputs, output: Outputs, session: Session): | |
| def filtered_df(): | |
| return combined_df[combined_df["sensor"].isin(input.sensor_dropdown())] | |
| def interactive_plot(): | |
| df = filtered_df() | |
| if input.graph_type_radio() == "line": | |
| fig = px.line( | |
| df, | |
| x=input.x_axis_dropdown(), | |
| y=input.y_axis_dropdown(), | |
| color="sensor", | |
| title=f"plot of {input.y_axis_dropdown()}", | |
| ) | |
| else: | |
| fig = px.scatter( | |
| df, | |
| x=input.x_axis_dropdown(), | |
| y=input.y_axis_dropdown(), | |
| color="sensor", | |
| title=f"plot of {input.y_axis_dropdown()}", | |
| ) | |
| fig.update_layout( | |
| plot_bgcolor="rgba(0,0,0,0)", | |
| paper_bgcolor="rgba(0,0,0,0)", | |
| xaxis=dict( | |
| showline=True, | |
| showgrid=True, | |
| linecolor="black", | |
| ), | |
| yaxis=dict( | |
| showline=True, showgrid=True, linecolor="black", gridcolor="lightgray" | |
| ), | |
| ) | |
| return fig | |
| # Create the Shiny app | |
| app = App(app_ui, server) | |
| # Run the app | |
| if __name__ == "__main__": | |
| app.run() | |