1
0

plotly.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """Component for displaying a plotly graph."""
  2. from typing import Any, Dict, List, Optional
  3. from reflex.components.component import NoSSRComponent
  4. from reflex.vars import Var
  5. try:
  6. from plotly.graph_objects import Figure
  7. except ImportError:
  8. Figure = Any # type: ignore
  9. class PlotlyLib(NoSSRComponent):
  10. """A component that wraps a plotly lib."""
  11. library = "react-plotly.js@2.6.0"
  12. lib_dependencies: List[str] = ["plotly.js@2.22.0"]
  13. class Plotly(PlotlyLib):
  14. """Display a plotly graph."""
  15. tag: str = "Plot"
  16. is_default: bool = True
  17. # The figure to display. This can be a plotly figure or a plotly data json.
  18. data: Optional[Var[Figure]] = None
  19. # The layout of the graph.
  20. layout: Optional[Var[Dict]] = None
  21. # The config of the graph.
  22. config: Optional[Var[Dict]] = None
  23. # The width of the graph.
  24. width: Optional[Var[str]] = None
  25. # The height of the graph.
  26. height: Optional[Var[str]] = None
  27. # If true, the graph will resize when the window is resized.
  28. use_resize_handler: Optional[Var[bool]] = None