dave on Nostr: import dash import dash_core_components as dcc import dash_html_components as html ...
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import dash_table
# Create the Dash app
app = Dash(__name__)
# Read the Data
df = pd.read_csv('data.csv')
# Create a Dash Layout
app.layout = html.Div([
# Add a header and a paragraph
html.H1("Dashboard Showing DatePickerSingle"),
html.P("This dashboard filters data based on DatePickerSingle"),
# Add a DataTable
dcc.DatePickerSingle(
id='date_picker_single',
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
initial_visible_month=df['date'].min(),
date=df['date'].max()
),
# Add a Table
dash_table.DataTable(id='table', data=df.to_dict('records'), columns=[{"name": i, "id": i} for i in df.columns])
])
# Update the Index
@app.callback(
Output('table', 'data'),
[Input('date_picker_single', 'date')])
def update_table(selected_date):
# Filter the data based on the selected date
filtered_df = df[df['date'] == selected_date]
# Create the Table
table_data = filtered_df.to_dict("rows")
return table_data
# Run the Dash app
if __name__ == '__main__':
app.run_server(debug=True)
Published at
2023-01-09 15:38:05Event JSON
{
"id": "35f0cbd267f39eafdb4d0e0131ec9ffc0866e0ee725c843c629899f1e92acefd",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1673278685,
"kind": 1,
"tags": [
[
"e",
"00095b6ff9e21cb9be57d55eb615386abb2b7c14ec2cad2398561a47bac3119e",
"",
"root"
],
[
"e",
"000c5d9c401e84b1fe7edbf18442e085677c80796b247d3f9357c8a3bd22f2c8",
"",
"reply"
],
[
"p",
"9f5e70ecf99a0ac6171ca014885aeb93843ba869c679209e2ea4bb61b586da7d"
]
],
"content": "import dash\nimport dash_core_components as dcc\nimport dash_html_components as html\nimport pandas as pd\nimport dash_table\n\n# Create the Dash app\napp = Dash(__name__)\n\n# Read the Data\ndf = pd.read_csv('data.csv')\n\n# Create a Dash Layout\napp.layout = html.Div([\n # Add a header and a paragraph\n html.H1(\"Dashboard Showing DatePickerSingle\"),\n html.P(\"This dashboard filters data based on DatePickerSingle\"),\n # Add a DataTable\n dcc.DatePickerSingle(\n id='date_picker_single',\n min_date_allowed=df['date'].min(),\n max_date_allowed=df['date'].max(),\n initial_visible_month=df['date'].min(),\n date=df['date'].max()\n ),\n # Add a Table\n dash_table.DataTable(id='table', data=df.to_dict('records'), columns=[{\"name\": i, \"id\": i} for i in df.columns])\n])\n\n\n# Update the Index\n@app.callback(\n Output('table', 'data'),\n [Input('date_picker_single', 'date')])\ndef update_table(selected_date):\n # Filter the data based on the selected date\n filtered_df = df[df['date'] == selected_date]\n\n # Create the Table\n table_data = filtered_df.to_dict(\"rows\")\n\n return table_data\n\n\n# Run the Dash app\nif __name__ == '__main__':\n app.run_server(debug=True)",
"sig": "f37fe78f66cf48434e6845e279069bff91441888487463db1f4d60f7097f57a390fe82cde06bc4178f4c2a8b0d9cb48701b0735cf89727ed2d26367b402794e2"
}