{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from dash import Dash, html, dcc, callback, Output, Input\n", "import plotly.express as px\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')\n", "\n", "app = Dash(__name__)\n", "\n", "app.layout = html.Div([\n", " html.H1(children='Dash Test App', style={'textAlign':'center'}),\n", " dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),\n", " dcc.Graph(id='graph-content')\n", "])\n", "\n", "@callback(\n", " Output('graph-content', 'figure'),\n", " Input('dropdown-selection', 'value')\n", ")\n", "def update_graph(value):\n", " dff = df[df.country==value]\n", " return px.line(dff, x='year', y='pop')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "app.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 4 }