3

FWIW: working on Python 3.10, Plotly 5.5.0, streamlit 1.8.1; OS: Ubuntu (WSL2).

I have successfully used the plotly.graph_objects Figure object in the plotly API to build a 3D plot that gets animated (using frames in the Figure) when pressing a 'Play' button or manually using the slider. The plot is shown on a Streamlit app via st.plotly_chart

The plot can be manipulated and viewed from any angle with the mouse, however whenever the animation gets played, the view angle is always reset to the same angle, while I need to be able to play the animation from whatever angle I'd like.

Example: enter image description here

Notice how I first manually turn around the plot with the cursor, then press play, and the figure (made up of several traces, one per facet) automatically resets its view angle before playing the frames that make up the animation. I want to avoid that behavior and be able to play the frames from the angle I manually set with the mouse.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Clem
  • 43
  • 5
  • 1
    Study the session_state at https://docs.streamlit.io/library/api-reference/session-state. By design streamlit will run the script from top to bottom and if you don't save your variable on session_state the initial value of your variable will be repeated. – ferdy Apr 21 '22 at 03:21
  • Hi ferdy and thanks for your answer. I know what Streamlit's session state is but I'm not sure this is a fix as st.plotly_chart is not a widget that can be given a key for storage in the session state dictionary – Clem Apr 21 '22 at 11:03
  • You manually rotate the axes, have a look in plotly resources if you can get a rotation reference of the axes. – ferdy Apr 21 '22 at 23:40
  • I have tried to get the 'camera' coords and put them in the session_state but didn't work – Clem Apr 22 '22 at 08:54
  • Can you get the latest camera values after setting the figure with your mouse? – ferdy Apr 23 '22 at 01:23
  • No. I might opt for Dash instead of Streamlit to avoid this unnecessary overhead. – Clem Apr 25 '22 at 11:23
  • I have partly solved my problem: after many successless tries, I've finally noticed that by commenting out `layout="wide"` in my `st.set_config()` block, I get the desired behaviour, that is, persistence of the user interaction (such as zoom, rotating the figure with the mouse e.g.). However, this is not a full fix as it only works at the beginning of a Streamlit session (e.g. right after refreshing the browser page) -> after any Streamlit widget interaction, camera is reset again. Using the `'uirevision'` argument in the figure layout didn't help either, unlike what I'd read in many threads. – Clem Apr 26 '22 at 15:15
  • Another approach without user mouse interaction on the figure is to expose the camera values into the widget. The user may rotate the figure not by mouse but by changing the values of the camera. Have you tried this idea? – ferdy Apr 27 '22 at 06:21
  • I haven't, as I reckon this would be way less user-friendly, interesting idea though – Clem Apr 27 '22 at 11:01
  • The issue I see is how to get the camera values when the user modifies the figure by using the mouse. Streamlit has nothing to do with this, the responsibility is on the plotly. – ferdy Apr 27 '22 at 11:37
  • Any solution or workaround found for this? – krips89 Feb 02 '23 at 12:49
  • hi @krips89, not to my knowledge – Clem Feb 02 '23 at 16:16

0 Answers0