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:40:40Event JSON
{
"id": "85c0a48838666f1626ad16819ba9038f795d9bb63a39fab60286e3a3b8be7394",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1673278840,
"kind": 1,
"tags": [
[
"e",
"00095b6ff9e21cb9be57d55eb615386abb2b7c14ec2cad2398561a47bac3119e",
"",
"root"
],
[
"e",
"000437ee83a1e2bb934db8f0650070f9cf8ef844c0d5af7d6382c3711509d781",
"",
"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": "b9c5541edf6d34f4b95a569d7c8972aa3e249cabb0b656fc8db6e73c25f97808e6d16463e00c8a9bc77fd00a0f493cc4d4a3705c12fc357bae698c18c0d084b0"
}