miletus on Nostr: from dash import Dash, dcc, html, Input, Output, dash_table import pandas as pd # ...
from dash import Dash, dcc, html, Input, Output, dash_table
import pandas as pd
# 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:43:00Event JSON
{
"id": "00043a4c7bdc81f8cfdd961fbff3be013ff677000378a4889ae522643a73400a",
"pubkey": "9f5e70ecf99a0ac6171ca014885aeb93843ba869c679209e2ea4bb61b586da7d",
"created_at": 1673278980,
"kind": 1,
"tags": [
[
"nonce",
"2201",
"12"
],
[
"p",
"5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"wss://nostr.drss.io"
],
[
"p",
"9f5e70ecf99a0ac6171ca014885aeb93843ba869c679209e2ea4bb61b586da7d",
"wss://nostr.drss.io"
],
[
"e",
"54d2d57113619d3e02dc64e69aba0a1876eba1b938033a44cad87460eacf5584",
"wss://nostr.drss.io",
"reply"
],
[
"e",
"00095b6ff9e21cb9be57d55eb615386abb2b7c14ec2cad2398561a47bac3119e",
"wss://nostr.drss.io",
"root"
],
[
"client",
"BIJA"
]
],
"content": "from dash import Dash, dcc, html, Input, Output, dash_table\nimport pandas as pd\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": "24098d24ab07eec9111e2bd3323febbf29fe3c821e1f5ec9137e2dc76529fbc285f64952a31e24dc515a208b10128a06b97f6c90071c601e78ee9a7aa4a28664"
}