Created
July 1, 2020 23:32
-
-
Save tashrifbillah/304fd47b14a6c6bce6b7572b555514d7 to your computer and use it in GitHub Desktop.
Displaying *png, *jpg image on a dash app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import base64 | |
import dash_html_components as html | |
from dash.dependencies import Input, Output | |
import dash_core_components as dcc | |
app = dash.Dash(__name__) | |
test_png = r'C:\Users\tashr\Downloads\20190318_114007.jpg' | |
app.layout = html.Div([ | |
html.Img(id='img'), | |
dcc.Input(id='var1') | |
]) | |
@app.callback(Output('img', 'src'), | |
[Input('var1', 'value')]) | |
def dash_img(var1): | |
test_base64 = base64.b64encode(open(test_png, 'rb').read()).decode('ascii') | |
return 'data:image/png;base64,{}'.format(test_base64) | |
if __name__ == '__main__': | |
app.run_server(debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment