Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
Changing the favicon in Flask/Dash

Trying to get the favicon to load I have followed suggestions from the internet:

server = Flask(__name__, static_folder='static')
app =  dash.Dash(external_stylesheets=external_stylesheets, server=server)

app.css.config.serve_locally = False
app.scripts.config.serve_locally = True

@server.route('/favicon.ico')
def favicon():
    print('Server root path', server.root_path)
    return send_from_directory(os.path.join(server.root_path, 'static'),
                               'dice.ico', mimetype='image/vnd.microsoft.icon')

   ...
   app.run_server(debug=True)

If I browse to the favicon, I see it:

http://www.example.com/favicon.ico

However, when I browse to

http://www.example.com

I see the dash default icon with it's own description. How do I ensure my ownfavicon loads correctly?

over 4 years ago · Santiago Trujillo
6 Respostas
Responde à pergunta

0

You can just put title="My Title" as an argument when establishing the Dash app instance. i.e.

app = dash.Dash(
    __name__,
    title="My Title",
    server=server,
    routes_pathname_prefix='/dash/'
)
over 4 years ago · Santiago Trujillo Relatório

0

An alternative used in Dash is:

app = dash.Dash()
app._favicon = ("path_to_folder/(your_icon).co")
over 4 years ago · Santiago Trujillo Relatório

0

You should create an "assets" folden and then update the "__favicon" property in your Dash app:

app._favicon = "favico.ico"
over 4 years ago · Santiago Trujillo Relatório

0

Adding for the sake of completeness. Nowadays, it's recommended to use a bundle of icons with different resolutions to please different browsers and ensure the best picture quality. You can produce such a bundle with the help of, say, realfavicongenerator.net Or you simply might want to use a non-standard .png or .svg icon.

For that, you can subclass Dash and add your much desired link rel and meta tags to its interpolate_index method:

import dash

class CustomDash(dash.Dash):
    def interpolate_index(self, **kwargs):
        return '''
<!DOCTYPE html>
<html>
    <head>
        {metas}
        <title>{title}</title>

        <link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png">
        <link rel="icon" type="image/png" sizes="32x32" href="assets/favicons/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="assets/favicons/favicon-16x16.png">
        <link rel="manifest" href="assets/favicons/site.webmanifest">
        <link rel="mask-icon" href="assets/favicons/safari-pinned-tab.svg" color="#5bbad5">
        <meta name="msapplication-TileColor" content="#da532c">
        <meta name="theme-color" content="#ffffff">

        {css}
    </head>
    <body>
        {app_entry}
        <footer>
            {config}
            {scripts}
            {renderer}
        </footer>
    </body>
</html>
        '''.format(**kwargs)
            
app = CustomDash()

Do not forget to place the unzipped bundle into your assets/favicons subfolder!

over 4 years ago · Santiago Trujillo Relatório

0

Even if OP's accepted answer doesn't work, refer to official document which says:

It is recommended to add name to the dash init to ensure the resources in the assets folder are loaded, eg: app = dash.Dash(name, meta_tags=[...]). When you run your application through some other command line (like the flask command or gunicorn/waitress), the main module will no longer be located where app.py is. By explicitly setting name, Dash will be able to locate the relative assets folder correctly.

Include __name__ in Dash object:

app = Dash(__name__)
over 4 years ago · Santiago Trujillo Relatório

0

To simply change the favicon all you need to do is to create a folder called assets next to your app.py and place your favicon.ico inside of that folder and it will work perfectly.

app.py:

import flask
import dash
import dash_html_components as html

server = flask.Flask(__name__)

@server.route('/')
def index():
    return 'Hello Flask app'

app = dash.Dash(
    __name__,
    server=server,
    routes_pathname_prefix='/dash/'
)

app.layout = html.Div("My Dash app")

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

Here is the docs link for more information: Dash docs

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda