For testing purpose, I have implemented a simple Bokeh chart with a deque() input and randomly generated streaming data. When running, the chart in streamlit keeps on blinking/flickering.
Instead, the same simple chart with Plotly.express does not have this problem.
Is there a way to fix this? Thanks.
Bokeh code:
import streamlit as st
from random import randint
from time import sleep
from collections import deque
from bokeh.plotting import figure
placeholder = st.empty()
y = deque()
x = deque()
count = 0
def data_streaming(price, time, index):
while len(price) <= 1000:
rnd = randint(50, 200)
index += 1
if len(y) > 10:
y.popleft()
x.popleft()
price.append(rnd)
time.append(index)
sleep(0.2)
print(βy:β, price[-1])
print(βx:β, time[-1])
with placeholder.container():
chart = figure(
title=βPrice Trend Analysis By Bookehβ,
x_axis_label=βxβ,
y_axis_label=βyβ)
chart.line(x, y, legend_label=βTrendβ, line_width=2)
st.write(chart)
sleep(0.1)
data_streaming(y, x, count)
Plotly.express code:
import streamlit as st
from random import randint
from time import sleep
from collections import deque
import plotly.express as px
placeholder = st.empty()
y = deque()
x = deque()
count = 0
def data_streaming(price, time, index):
while len(price) <= 1000:
rnd = randint(50, 200)
index += 1
if len(y) > 10:
y.popleft()
x.popleft()
price.append(rnd)
time.append(index)
sleep(0.2)
print(βy:β, price[-1])
print(βx:β, time[-1])
with placeholder.container():
fig = px.line(x=x, y=y)
st.write(fig)
sleep(0.1)
index += 1
data_streaming(y, x, count)