Reload Graph When Input in Textbox Changes

Hello everyone, I have just used Dash few hours and am now doing my first project with it. Pretty useful so thank you so much.

I have a situation at the moment where I am stuck on making my graph to change whenever the input in textbox changes. I also wanted to make sure that whenever changes made to the textbox, it will reflect to the output I wanted from the DB [the graph] and this should be done continuously ie the graph will flow continuously.

However after some tries in using a button to kickstart the n-intervals, I still failed in doing so.

It’d will be great if anyone can have a look at my code. Thank you so much.

Below is my code:

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque
import sqlite3
import pandas as pd
import time
#popular topics: google, olympics, trump, gun, usa

external_stylesheets = ['']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(
    [   html.H2('Live Twitter Sentiment Trend'),
        dcc.Input(id='sentiment_term', value='trump', type='text'),
        dcc.Graph(id='live-graph', animate=False),
            n_intervals = 0

    Output('live-graph', 'figure'),
    [Input(component_id='sentiment_term', component_property='value'),
    [Input(component_id='graph-update', component_property='n_intervals')])

def update_graph_scatter(sentiment_term):
        conn = sqlite3.connect('twitter.db')
        df = pd.read_sql("SELECT * FROM sentiment WHERE tweet LIKE ? ORDER BY unix DESC LIMIT 1000", conn ,params=('%' + sentiment_term + '%',))
        df.sort_values('unix', inplace=True)
        df['sentiment_smoothed'] = df['sentiment'].rolling(int(len(df)/2)).mean()

        df['date'] = pd.to_datetime(df['unix'],unit='ms')
        df.set_index('date', inplace=True)

        df = df.resample('0.15min').mean()
        X = df.index
        Y = df.sentiment_smoothed

        data = plotly.graph_objs.Scatter(
                mode= 'lines+markers'

        return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),
                                                    title='Term: {}'.format(sentiment_term))}

    except Exception as e:
        with open('errors.txt','a') as f:

if __name__ == '__main__':

@stynxsilver your callback pie syntax has a little problem, it should be sth like this

    Output("live-graph", "figure"),
    [Input("sentiment_term", "value"), Input("graph-update", "n_intervals")],
def update_graph_scatter(term, interval):

It fixed my situation. Thank you so much!