# Update html.Embed element with dropdown

**URL:** <https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782>\
**Category:** Dash Python\
**Created:** [July 5, 2017, 6:18pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782 "2017-07-05T18:18:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpsempek](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@cpsempek](https://community.plotly.com/u/cpsempek)\
**Post date:** [July 5, 2017, 6:18pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/1 "2017-07-05T18:18:22Z")

</div>

I am trying to populate a dropdown with emebed urls pointing to plotly plots on the plotly server, and then have the dropdown update an html.Embed object’s `src` parameter so that the embedded plot changes when a new value is selected in the dropdown. I cannot get it to work properly. The embedded plots do not show up, not sure what I am doing wrong.

(Made a few edits). Here is my code:

```
# update embedded plotly plot with drowdown

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

# plotly plot embed urls
embed_urls = {
    'plot_1': 'https://plot.ly/~om_ad_ops/69140.embed',
    'plot_2': 'https://plot.ly/~om_ad_ops/69138.embed'
}

# initialize Dash object
app = dash.Dash()

# define dropdown whose options are embed urls
dd = dcc.Dropdown(      
    id='dropdown',
    options= [{'label': k, 'value': v} for k, v in embed_urls.iteritems()], 
    value=embed_urls.keys()[0],
)

# embedded plot element whose `src` parameter will
# be populated and updated with dropdown values
plot = html.Embed(
    id='plot',
    height=600, 
    width=1000
)

# set div containing dropdown and embedded plot
app.layout = html.Div(children=[dd, plot])

# update `src` parameter on dropdown select action
@app.callback(
    Output(component_id='plot', component_property='src'),
    [Input(component_id='dropdown', component_property='value')]
)
def update_plot_src(input_value):
    
    return input_value

if __name__ == ' __main__':

    app.run_server(debug=True)

```

Here are the plots being used:  
[https://plot.ly/~om\_ad\_ops/69140](https://plot.ly/~om_ad_ops/69140)  
[https://plot.ly/~om\_ad\_ops/69138](https://plot.ly/~om_ad_ops/69138)

Please let me know if I should provide anything else.

Best,  
Connor

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [July 5, 2017, 10:37pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/2 "2017-07-05T22:37:38Z")

</div>

Your code looks mostly good! This is a really cool example. Try just replacing `html.Embed` with `html.Iframe`. You’ll probably want to style the iframe as well with something like `style={'border': 'none', 'width': '100%', 'height': 500}` as the browser’s default `iframe` styling is pretty rough 🙈

---

<div class="post-metadata">

**Author:** ![cpsempek](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@cpsempek](https://community.plotly.com/u/cpsempek)\
**Post date:** [July 5, 2017, 11:13pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/3 "2017-07-05T23:13:26Z")

</div>

Awesome, that did the trick. Here is the updated working code.

```
# update embedded plotly plot with dropdown

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

# plotly plot embed urls
urls = {
    'plot_1': 'https://plot.ly/~om_ad_ops/69140.embed',
    'plot_2': 'https://plot.ly/~om_ad_ops/69138.embed'
}

init_key, init_val = urls.iteritems().next()

# initialize Dash object
app = dash.Dash()

# define dropdown whose options are embed urls
dd = dcc.Dropdown(      
    id='dropdown',
    options= [{'label': k, 'value': v} for k, v in urls.iteritems()],
    placeholder=init_key
)

# embedded plot element whose `src` parameter will
# be populated and updated with dropdown values
plot = html.Iframe(
    id='plot',
    style={'border': 'none', 'width': '100%', 'height': 500},
    src=init_val
)

# set div containing dropdown and embedded plot
app.layout = html.Div(children=[dd, plot])

# update `src` parameter on dropdown select action
@app.callback(
    Output(component_id='plot', component_property='src'),
    [Input(component_id='dropdown', component_property='value')]
)
def update_plot_src(input_value):
    
    return input_value

if __name__ == ' __main__':

    app.run_server(debug=True)

```

One last question. I set the default value selected by the dropdown using the `placeholder` parameter. However, this does not automatically populate the `src` parameter in `html.Iframe`. So, I tried forcing that to a default value using `src=init_value`, but this still does not display a plot on page load.

Also, I removed the `value` parameter from the dropdown, it was creating a very weird nested set of dropdown menus (see screen shot below).

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/479d3a94d5383982c0b01bb821c59d4005ad8431.png)

Super happy with the code as is though, thanks again!

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [July 6, 2017, 4:08pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/4 "2017-07-06T16:08:41Z")

</div>

> [@cpsempek](#):
>
> One last question. I set the default value selected by the dropdown using the placeholder parameter.

The default parameter is actually just `value`: try replacing `placeholder` with `value`. `placeholder` is used just as a “hint” to the user (unfortunately, some research shows that [placeholders aren’t that intuitive or helpful](https://www.nngroup.com/articles/form-design-placeholders/))

---

<div class="post-metadata">

**Author:** ![cpsempek](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@cpsempek](https://community.plotly.com/u/cpsempek)\
**Post date:** [July 6, 2017, 4:33pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/5 "2017-07-06T16:33:32Z")

</div>

> [@chriddyp](#):
>
> The default parameter is actually just value: try replacing placeholder with value. placeholder is used just as a “hint” to the user (unfortunately, some research shows that placeholders aren’t that intuitive or helpful)

great, thanks chriddyp!

---

<div class="post-metadata">

**Author:** ![Dee](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Dee](https://community.plotly.com/u/Dee)\
**Post date:** [October 25, 2017, 5:41pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/6 "2017-10-25T17:41:20Z")

</div>

> [@chriddyp](#):
>
> style={‘border’: ‘none’, ‘width’: ‘100%’, ‘height’: 500}

The question is how does one set up an auto detect for the height and width of the page. tried it but I kept getting a minimised height. i.e is `style={'border': 'none', 'width': 'auto', 'height': 'auto'}`. It would be wonderful to get the full syntax for the `html.iframe` in Dash

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [October 25, 2017, 7:10pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/7 "2017-10-25T19:10:10Z")

</div>

> [@Dee](#):
>
> It would be wonderful to get the full syntax for the html.iframe in Dash

The `style` property just renders the `dict` as inline-css, so all CSS properties that are available for `iframe` are available in the `html.Iframe(style={...})`

---

<div class="post-metadata">

**Author:** ![Dee](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Dee](https://community.plotly.com/u/Dee)\
**Post date:** [October 25, 2017, 9:30pm UTC](https://community.plotly.com/t/update-html-embed-element-with-dropdown/4782/8 "2017-10-25T21:30:32Z")

</div>

> [@chriddyp](#):
>
> n Dash
> 
> The style property just renders the dict as inline-css, so all CSS p

Thanks for the quick response
