I want to build out a weather forecast that displays on my dashboard. This means returning text and images for 5 days or so. I suspect I want to build this and return a “block” of HTML rather than having a callback for each “img src” and “children” for text? Are there examples of returning a built block of HTML in a callback Return?
Thanks,
Eric
Hi @tangedahl
I might be missing something here, but you could just return the children property of the Div() component and put all your content in there like the example below
from dash import Dash, html, Output, Input
app = Dash(__name__)
app.layout = html.Div([
html.Button('Click me', id='button'),
html.Div(id='output')
])
@app.callback(
Output('output', 'children'),
[Input('button', 'n_clicks')]
)
def update_output(n_clicks):
if n_clicks is None:
return ''
return html.Div([
html.H1('Hello, Dash!'),
html.P('This is an HTML block.')
])
if __name__ == '__main__':
app.run_server(debug=True)
OK, thanks yes that might be the way to do that in a block.
I am looking at exploring the dash_bootstrap_components to build a table and then return “Table”. Any issues with this method??
table_header = [
html.Thead(html.Tr([html.Th(text), html.Th(“Last Name”)]))
]
row1 = html.Tr([html.Td(“Arthur”), html.Td(“Dent”)])
row2 = html.Tr([html.Td(“Ford”), html.Td(“Prefect”)])
row3 = html.Tr([html.Td(“Zaphod”), html.Td(“Beeblebrox”)])
row4 = html.Tr([html.Td(“Trillian”), html.Td(“Astra”)])
table_body = [html.Tbody([row1, row2, row3, row4])]
table = dbc.Table(table_header + table_body, bordered=True)