Krishna
Krishna

Reputation: 1362

infinite scrolling without button with python dash

As discussed here, the following code can simulate infinite scrolling with a button at the end of the page

app.layout=html.Div(
    id='output',
    children=[
        html.Div("Thing 1")
    ],
    html.Button("Load more",id='load-new-content',n_clicks=0)
)

@app.callback(
    Output('output','children'),
    [Input('load-new-content','n_clicks')],
    [State('output','children')])
def more_output(n_clicks,old_output):
    if n_clicks==0:
        raise PreventUpdate
    return old_output + [html.Div('Thing {}'.format(n_clicks))]

Is there a way to achieve the same without a button?

Is it possible to trigger the same callback on an event like scrolling to the bottom of the page?

Preferably in python and dash, without going into Java Scripting

Upvotes: 0

Views: 661

Answers (1)

coralvanda
coralvanda

Reputation: 6596

Probably not without getting into some JS, unless you can find a custom component that someone created which is already available.

Essentially, you need a way to trigger a Dash callback with something like a scroll action, or the vertical scroll hitting the bottom. Neither of those things is connected to Dash through the core component library (dcc). That means a custom component that can trigger a callback based on listening to an event like that would be required.

Upvotes: 1

Related Questions