Skip to content

Passing meta tags to <head> and <footer> #170

Closed

Description

@radumas

I raised this on the community forum here when I wanted to add <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> to the <head> of my app.

I noticed the <head> section gets defined by the index() function and so created a subclass of Dash to add the tag above.

class Dash_responsive(dash.Dash):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    #Overriding from https://github.com/plotly/dash/blob/master/dash/dash.py#L282
    def index(self, *args, **kwargs):
        scripts = self._generate_scripts_html()
        css = self._generate_css_dist_html()
        config = self._generate_config_html()
        title = getattr(self, 'title', 'Dash')
        return ('''
        <!DOCTYPE html>
        <html>
            <head>
                <meta charset="UTF-8"/>
                <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
                <title>{}</title>
                {}
            </head>
            <body>
                <div id="react-entry-point">
                    <div class="_dash-loading">
                        Loading...
                    </div>
                </div>
            </body>
            <footer>
                {}
                {}
            </footer>
        </html>
        '''.format(title, css, config, scripts))

app = Dash_responsive()

More generally, I propose app should have a head() and footer() function to add extra tags to either section which would get added to index()

Activity

  1. chriddyp commented on Jun 8, 2018

    @chriddyp
    Member

    A broader proposal for this in outlined in #265

  2. amarvin commented on Jun 20, 2018

    @amarvin

    This would be wonderful! I'm trying to add this meta tag into my Dash apps:
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    My Dash app will be deployed as an Intranet app, IE11 must be supported, and the company's IE11 compatibility view settings make all Intranet pages render in compatibility mode. This compatibility mode leads to some JavaScript libraries to not load correctly (e.g. it thinks react.min.js has "Expected identifier, string or number"). Adding this meta tag would prevent IE11 from using compatibility mode when rendering the Dash app. More info on https://stackoverflow.com/q/25557299/6068036.

  3. chriddyp commented on Jun 20, 2018

    @chriddyp
    Member

    Thanks for reporting @amarvin ! That seems like it might even be a tag that we should include by default.

  4. amarvin commented on Jun 21, 2018

    @amarvin

    That'd be perfect!

  5. T4rk1n commented on Oct 12, 2018

    @T4rk1n
    Contributor

    Can add meta tags from #265

  6. added a commit that references this issue on May 21, 2019
  7. added a commit that references this issue on May 28, 2021
  8. added a commit that references this issue on Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions