RHercock/Bio-test
0
1# filename: color_blocks.py2 3import dash4from dash import dcc5from dash import html6import plotly.graph_objects as go7import numpy as np8import random9from dash.dependencies import Input, Output, State10import time11 12# Create a 2D array of random integers between 0 and 25613array = np.random.randint(0, 256, (10, 10))14 15app = dash.Dash(__name__)16 17app.layout = html.Div(18 children=[19 dcc.Graph(id='live-update-graph'),20 dcc.Interval(21 id='interval-component',22 interval=200, # in milliseconds23 n_intervals=024 )25 ]26)27 28@app.callback(Output('live-update-graph', 'figure'),29 Input('interval-component', 'n_intervals'))30def update_graph_live(n):31 # Choose a random block32 x, y = random.randint(0, array.shape[0]-1), random.randint(0, array.shape[1]-1)33 # Update its value34 array[x, y] = random.randint(0, 256)35 36 # Create a heatmap37 fig = go.Figure(data=go.Heatmap(38 z=array,39 colorscale='Spectral', # change to the colorscale of your choice40 colorbar=dict(nticks=10, tickvals=list(range(0, 257, 32)), tickmode='array'),41 ))42 43 fig.update_layout(autosize=False, width=500, height=500, margin=dict(l=50, r=50, b=100, t=100, pad=4))44 45 return fig46 47if __name__ == '__main__':48 app.run_server(debug=True)49 50 51 