Read updated textfile

Hi
I have just started to use Dash. My final goal is to develop a dashboard to simulate buildig energy and exchange CAD data but right now I just trying to read data from a local textfile that is being updated one per second. The examples I found at https://dash.plot.ly/live-updates contains so many aspects so I wonder if someone could help me with an simple example, just reading data once per second and visualize this on a page.

/Max

This is a well paced tutorial (though a little outdated, go back to the official documentation after it to check out the new features) that probably includes most the stuff you want: https://pythonprogramming.net/data-visualization-application-dash-python-tutorial-introduction/

1 Like

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, Event, State
import os
path1 = os.path.join(’/Users/giovannicruz/Documents/’, ‘Storm2018.txt’)

app = dash.Dash(name)

app.layout = html.Div(style={‘backgroundColor’: ‘white’, ‘color’: ‘black’}, children=[

                            dcc.Input(
                                    id = 'text-input',
                                    placeholder = '', style= dict(display = "none"),
                                    type = 'text',
                                    value = ''),
                            
                            html.Div(id = 'text-display'),

                  
                                dcc.Interval(id='text-interval',
                                             interval = 1000)
                                     ])

@app.callback(
Output(‘text-display’,‘children’),
[Input(‘text-input’,‘value’)],
events=[Event(‘text-interval’, ‘interval’)])
def update_text_output_2(input_value):
with open(path1, ‘r’) as Texlist1:
content = Texlist1.read()
return content

if name == “main”:
app.run_server(debug=True)

1 Like