Using a logfile that is produced by a long computation and refresh it into a pre tag.
Scripted with a JS function (not inline) that can be toggled on or off, instead of always on.
I have tried to adapt solution from the accepted answer here Display the contents of a log file as it is updated into function and it does not work as expected because it does not render.
Log File is changed by another software accordingly.
Flasks Python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html',
str_log = url_for('static',log.txt"))
@app.route('/', methods=['POST'])
def all_forms_post():
if request.method == 'POST':
if request.form['id_form'] == 'I.2':
#do code that changes log.txt
index
return redirect(request.url)
return redirect(request.url)
HTML
<form method="post" action="/" enctype="multipart/form-data">
<input type="hidden" name="id_form" value="I.2" />
<input type="submit" name="btn" value="simulate" onclick="refreshPre('{{ str_log }}', true)" />
</form>
<pre id="contents">
Hello click button to start simulation and update this
</pre>
JS
// global JavaScript Variables here
var timerId;
/*Fetches*/
function refreshPre(url, blRefresh = true) {
if (blRefresh) {
// declare and assign setInterval
timerId = window.setInterval(populatePre(url),1000);
} else {
// stop setInterval
window.clearInterval(timerId);
timerId = null;
}
}
function populatePre(url) {
var output = document.getElementById('contents');
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
}
Ideas are very appreciated cheers.