Twitter Publish widget in a Dash app

Hi everyone,

I’m quite new to Dash and was wondering if someone has already done this before. I’m trying to embed a Twitter publish widget in my Dash app. Is there a way I can get the following code from HTML to the usual Plotly Dash’s syntax?

<a class="twitter-timeline" data-width="400" data-height="400" href="https://twitter.com/DavidLojkasek?ref_src=twsrc%5Etfw">Tweets by DavidLojkasek</a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

Any help is appreciated!

Thank you!

dalo

Hi @dalo,

You can directly paste the code snippet from Twitter Publish inside the srcDoc attribute of html.Iframe.

Here’s a working example:

from dash import Dash, html

app = Dash()
app.layout = html.Div([
    html.Iframe(
        srcDoc='''
            <a class="twitter-timeline" data-theme="light" href="https://twitter.com/elonmusk?ref_src=twsrc%5Etfw">
                Tweets by Elon Musk
            </a> 
            <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
        ''',
        height=800,
        width=300
    )
])

if __name__ == '__main__':
    app.run_server()

2 Likes

Thank you, @atharvakatre! This is very helpful!

1 Like