test_plotly.py 585 B

1234567891011121314151617181920212223
  1. import plotly.graph_objects as go
  2. from nicegui import ui
  3. from .screen import Screen
  4. def test_plotly(screen: Screen):
  5. fig = go.Figure(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name='Trace 1'))
  6. fig.update_layout(title='Test Figure')
  7. plot = ui.plotly(fig)
  8. ui.button('Add trace', on_click=lambda: (
  9. fig.add_trace(go.Scatter(x=[0, 1, 2], y=[2, 1, 0], name='Trace 2')),
  10. plot.update()
  11. ))
  12. screen.open('/')
  13. screen.should_contain('Test Figure')
  14. screen.click('Add trace')
  15. screen.should_contain('Trace 1')
  16. screen.should_contain('Trace 2')