Browse Source

Add config to rx.plotly component (#2745)

Amir Molavi 1 year ago
parent
commit
842c7e6882

+ 3 - 0
reflex/components/plotly/plotly.py

@@ -32,6 +32,9 @@ class Plotly(PlotlyLib):
     # The layout of the graph.
     layout: Var[Dict]
 
+    # The config of the graph.
+    config: Var[Dict]
+
     # The width of the graph.
     width: Var[str]
 

+ 2 - 0
reflex/components/plotly/plotly.pyi

@@ -103,6 +103,7 @@ class Plotly(PlotlyLib):
         *children,
         data: Optional[Union[Var[Figure], Figure]] = None,  # type: ignore
         layout: Optional[Union[Var[Dict], Dict]] = None,
+        config: Optional[Union[Var[Dict], Dict]] = None,
         width: Optional[Union[Var[str], str]] = None,
         height: Optional[Union[Var[str], str]] = None,
         use_resize_handler: Optional[Union[Var[bool], bool]] = None,
@@ -165,6 +166,7 @@ class Plotly(PlotlyLib):
             *children: The children of the component.
             data: The figure to display. This can be a plotly figure or a plotly data json.
             layout: The layout of the graph.
+            config: The config of the graph.
             width: The width of the graph.
             height: The height of the graph.
             use_resize_handler: If true, the graph will resize when the window is resized.

+ 12 - 0
tests/components/graphing/test_plotly.py

@@ -1,5 +1,6 @@
 import numpy as np
 import plotly.graph_objects as go
+import reflex as rx
 import pytest
 
 from reflex.utils.serializers import serialize, serialize_figure
@@ -31,3 +32,14 @@ def test_serialize_plotly(plotly_fig: go.Figure):
     value = serialize(plotly_fig)
     assert isinstance(value, list)
     assert value == serialize_figure(plotly_fig)
+
+
+def test_plotly_config_option(plotly_fig: go.Figure):
+    """Test that the plotly component can be created with a config option.
+
+    Args:
+        plotly_fig: The figure to display.
+    """
+    
+    # This tests just confirm that the component can be created with a config option.
+    _ = rx.plotly(data=plotly_fig, config={"showLink": True})