I created a simpy simulation which changes the status of objects with time based on excel file I printed the results using print command in python, but I also would like to display the results on plotly dash.
what I tried
from dash import Dash, dcc, html, dash_table, Input, Output, State, callback
import base64
import datetime
import io
import simpy
import dash
import dash_cytoscape as cyto
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
import requests
import json
import datetime
import plotly
import pandas as pd
import numpy as np
import environment.settings as stngs
import random
import openpyxl
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
df = pd.read_csv("result.csv")
app = Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dbc.Card(
dbc.CardBody([
dbc.Row([
dcc.Interval(
id='interval-component',
interval=5000, # in milliseconds
n_intervals=0)
], align='start'),
dbc.Row([
html.Div(children=[dcc.Input(id='input-on-submit', type='number', value=80), 'Simulation duration']),
html.Button('Simulate', id='submit-val', n_clicks=0),
html.Div(id='run_event_sim_button',children='Enter a simulation duration'),
], align='start'),
])
),
html.Div(id='output-data-upload'),
])
@app.callback(Output('run_event_sim_button', 'children'),
Input('submit-val', 'n_clicks'),
State('input-on-submit', 'value'),
prevent_initial_call=True)
def run_event_sim(submit, value_duration):
def run_factory(env):
while True:
print(env.now)
for i in range(21):
print (df.iloc[i, 0] + ' ' + df.iloc[i, env.now+1])
yield env.timeout(1)
env = simpy.RealtimeEnvironment(initial_time=0, factor=5, strict=False)
env.process(run_factory(env))
env.run(until=10)
return 'Descrete event simulation was triggered'
if __name__ == '__main__':
app.run(debug=True,port=8051)
I get the right results displayed on python console but I need to display it on the dash