Using imge files in Dash App

Options
Usersyed
Usersyed Partner, Registered Posts: 29 Partner

Hi all,

I have an image file placed under the static web resources in Dataiku.
How do we specify the path for this image so that I can use this image in my Dash app?

Note: I am using an online instance of Dataiku and not on my local server.


Operating system used: Windows

Tagged:

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    edited July 17
    Options

    Hi @Usersyed
    ,

    Global Shared Code is not available on Dataiku Online instances at this time. So you will not be able to use static resources. You should instead use a Managed folder where you store the images and read from that folder.

    import plotly.express as px
    import dataiku
    import dash_core_components as dcc
    import dash_html_components as html
    import pandas as pd
    import plotly.graph_objects as go
    import dash
    import base64
    
    #replace images with the actual folder name
    folder = dataiku.Folder("images")
    
    with folder.get_download_stream("subfolder/test.png") as stream:
        encoded_image = base64.b64encode(stream.read())
        #print(encoded_image)
    
        app.layout = html.Div([
           html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode()))
           
        ])



  • Usersyed
    Usersyed Partner, Registered Posts: 29 Partner
    Options

    @AlexT
    Thank you for this solution.
    I will test this one also.
    I tried using "/local/static/image_name" as the file path and it worked.

  • hs987
    hs987 Registered Posts: 1
    Options

    Hi, how would this work in cases where you're using DataIku on a local server?

Setup Info
    Tags
      Help me…