Python Forum

Full Version: Get input for reading DB and refreshing plotly.graph_objects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

there is a simple Python appilaction, which reads data from SQL database and shows the result as plotly.graph_objects.

I want the get two values from UI for stock and day and read data from SQl database and show the data with plotly.graph_objects.
At the moment are both data hard coded:

stocksTicker = 'GRVI'
the_day='2021-10-14'

Could you please giv me some instractions how to extend the code to implement the requirements ?

Thanks in advance, Michel

df = pd.read_sql(selectString ,con=Engine)

trace1 = {
    'x': df.t_datetime,
    'open': df.o,
    'close': df.c,
    'high': df.h,
    'low': df.l,
    'type': 'candlestick',
    'name': stocksTicker,
    'showlegend': True
}

# Config graph layout
layout = go.Layout({
    'title': {
        'text': 'Moving Averages',
        'font': {
            'size': 15
        }
    }
})

fig=go.Figure([trace1])
fig.show()
(May-18-2022, 08:55 PM)michel77777 Wrote: [ -> ]Hi,

there is a simple Python appilaction, which reads data from SQL database and shows the result as plotly.graph_objects.

I want the get two values from UI for stock and day and read data from SQl database and show the data with plotly.graph_objects.
At the moment are both data hard coded:

stocksTicker = 'GRVI'
the_day='2021-10-14'

Could you please giv me some instractions how to extend the code to implement the requirements ?

Thanks in advance, Michel

df = pd.read_sql(selectString ,con=Engine)

trace1 = {
    'x': df.t_datetime,
    'open': df.o,
    'close': df.c,
    'high': df.h,
    'low': df.l,
    'type': 'candlestick',
    'name': stocksTicker,
    'showlegend': True
}

# Config graph layout
layout = go.Layout({
    'title': {
        'text': 'Moving Averages',
        'font': {
            'size': 15
        }
    }
})

fig=go.Figure([trace1])
fig.show()

solved