AttributeError: module 'dash_bootstrap_components' has no attribute 'PaginationItem' #958
-
according to the migration guide of dbc here is my demo code: import dash app = dash.Dash(name, external_stylesheets=[dbc.themes.BOOTSTRAP]) pagespagination = dbc.Pagination( page contentpage_1_layout = dbc.Container([ page_2_layout = dbc.Container([ page_3_layout = dbc.Container([ app.layout = dbc.Container([ @app.callback(Output("page-1", "style"), [Input("page-1", "n_clicks")]) @app.callback(Output("page-2", "style"), [Input("page-2", "n_clicks")]) @app.callback(Output("page-3", "style"), [Input("page-3", "n_clicks")]) if name == "main": |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @Davidyang1989 I don't see See the examples here. You should create a @app.callback(Output("page-content", "children"), Input("pagination", "active_page"))
def show_page_content(active_page):
if active_page == 1:
return page_1_content # can save this as a global variable or generate on the fly
elif active_page == 2:
return page_2_content
else:
# page not found: display error
return not_found_404_content If you have many pages, you might prefer to use a dictionary or similar to avoid long if-else statements, e.g. @app.callback(Output("page-content", "children"), Input("pagination", "active_page"))
def show_page_content(active_page):
# get content from PAGES dictionary, return 404 if key is not found
return PAGES.get(active_page, not_found_404) |
Beta Was this translation helpful? Give feedback.
Hey @Davidyang1989
I don't see
PaginationItem
listed anywhere in the migration guide or the docs?See the examples here. You should create a
Pagination
component and then use theactive_page
prop in your callbacks to respond accordingly. If you want to use the pagination component to navigate then you would do something like the following