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:39:16Event JSON
{
"id": "2276be8e9edf448904e1d00a80f2d1c9093813634f0a014ca6f94aa390e98279",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1673278756,
"kind": 1,
"tags": [
[
"e",
"00095b6ff9e21cb9be57d55eb615386abb2b7c14ec2cad2398561a47bac3119e",
"",
"root"
],
[
"e",
"0008a9fa4d1386577cc35617226c8550f04e87bb0a1ddf1477cab1736521a308",
"",
"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(\nOutput('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": "1e99ed1b116e7d2a9f19e65a10c6918413af93df8cb52d1a040304c96a72877be64596397bcdd621b70e8e7babe61c70053418805b3e98dff4d0c6c5bb1dc070"
}