I have created an onnline Plotly choropleth map with US map with states getting data from a database… I created an online html file at my plotly cloud account to be able to embed it in my custom webpage that is currently at localhost. I could not find how to embed this online plotly graph into my existing Dash app.layout code so that I show everything in the same web page. Below is the overall code:
- First i create an online Plotly choropleth map on my Plotly account. This works perfectly.
data = [ dict(
type=‘choropleth’,
locations = df[‘code’],
z = df[‘total exports’].astype(float),
locationmode = ‘USA-states’,
................................. Here I truncated the code for the sake of space................................
py.plot({"data":data, "layout":layout}, filename='US _Social_Sentiment_Map.html')
- Then I retrieved the generated HTML link from my plotly account’s embed HTML part for the above map. It looks something like this:
- Then I would like to embed the above Plotly choropleth map into below python Dash code and publish the map at the resultant website at http://127.0.0.1:8050/. I could not figure out how to embed it despite different trials. My Dash code (without the above map link) looks like below (source: Sentdex/socialsentiment/blob/master/dash_mess.py )
app = dash.Dash(name)
app.layout = html.Div([
html.Div(className='container-fluid', children=[html.H2('Live Twitter Sentiment', style={'color':"#CECECE"}),
html.H5('Search:', style={'color':app_colors['text']}),
dcc.Input(id='sentiment_term', value='twitter', type='text', style={'color':app_colors['someothercolor']}),
],
style={'width':'98%','margin-left':10,'margin-right':10,'max-width':50000}),
html.Div(className='row', children=[html.Div(id='related-sentiment', children=html.Button('Loading related terms...', id='related_term_button'), className='col s12 m6 l6', style={"word-wrap":"break-word"}),
html.Div(id='recent-trending', className='col s12 m6 l6', style={"word-wrap":"break-word"})]),
html.Div(className='row', children=[html.Div(dcc.Graph(id='live-graph', animate=False), className='col s12 m6 l6'),
html.Div(dcc.Graph(id='historical-graph', animate=False), className='col s12 m6 l6')]),
html.Div(className='row', children=[html.Div(id="recent-tweets-table", className='col s12 m6 l6'),
html.Div(dcc.Graph(id='sentiment-pie', animate=False), className='col s12 m6 l6'),]),
dcc.Interval(
id='graph-update',
interval=1*1000
),
dcc.Interval(
id='historical-update',
interval=60*1000
),
dcc.Interval(
id='related-update',
interval=30*1000
),
dcc.Interval(
id='recent-table-update',
interval=2*1000
),
dcc.Interval(
id='sentiment-pie-update',
interval=60*1000
),
], style={'backgroundColor': app_colors['background'], 'margin-top':'-30px', 'height':'2000px',},
)
Thanks for any suggestions or help.
Oz