0

I'm trying to get a button to jump/scroll to a certain part of the webpage using dash-bootstrap-components. The anchor is added to the URL correctly, but the webpage doesn't move.

import dash_html_components as html
import dash_bootstrap_components as dbc

layout = html.Div([
...
  html.Div([
    dbc.Button('Record Information', id='record-info-btn', href='#record-info'
                className='btn btn-orange align-middle btn btn-secondary')])
...
  html.Div([
    dbc.Form([
      html.Div([
        dbc.FormGroup([
          html.Div([
            html.H3('Record Information', id='record-info')
            ...
          ])
        ])
      ])
    ])
  ])
], className='whitContainerHalf')

I've tried using dbc.NavLink instead of Button, but the same thing happens.

2 Answers2

1

According to the dbc documentation, Button has an href field that can link to an internal id or an external url; however, according to an issue on their repo, it doesn't work for internal ids. You have to use html.A() to jump to the section.

import dash_html_components as html
import dash_bootstrap_components as dbc

layout = html.Div([
...
  html.Div([
    html.A(dbc.Button('Record Information', id='record-info-btn', 
                      className='btn btn-orange align-middle btn btn-secondary'), 
           href='#record-info')
  ])
...
  html.Div([
    dbc.Form([
      html.Div([
        dbc.FormGroup([
          html.Div([
            html.H3('Record Information', id='record-info')
            ...
          ])
        ])
      ])
    ])
  ])
], className='whiteContainerHalf')
0

I think this offers a better demonstration:

app.layout = html.Div([

   html.Div([
    html.A(dbc.Button('Record Information', id='record-info-btn'), 
           href='#record-info')
  ]),

  html.Div([
      html.Div([], style={'display': "block", 'height': "2000px"}),
          html.Div([
            html.H3('Record Information', id='record-info')
          ])
  ])
])
Sterling Butters
  • 1,024
  • 3
  • 20
  • 41