From 842c7e6882786a5764ecdf19076f4d223d9015c7 Mon Sep 17 00:00:00 2001 From: Amir Molavi Date: Wed, 28 Feb 2024 15:44:33 -0500 Subject: [PATCH] Add config to rx.plotly component (#2745) --- reflex/components/plotly/plotly.py | 3 +++ reflex/components/plotly/plotly.pyi | 2 ++ tests/components/graphing/test_plotly.py | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/reflex/components/plotly/plotly.py b/reflex/components/plotly/plotly.py index e0dd880db..7a0dd835f 100644 --- a/reflex/components/plotly/plotly.py +++ b/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] diff --git a/reflex/components/plotly/plotly.pyi b/reflex/components/plotly/plotly.pyi index 2a0653aeb..f9d3336d7 100644 --- a/reflex/components/plotly/plotly.pyi +++ b/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. diff --git a/tests/components/graphing/test_plotly.py b/tests/components/graphing/test_plotly.py index 2d676b1b9..4b04354fc 100644 --- a/tests/components/graphing/test_plotly.py +++ b/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}) \ No newline at end of file