
* init fix * Update reflex/components/plotly/plotly.py Co-authored-by: Masen Furer <m_github@0x26.net> * plotly: treat `data` as a `dict`-type Var in _render this allows the data to be passed directly as a figure or from a state var * removed width height prop as they are no longer needed * updated * reverted some of the changes * fixed unit tests * regen pyi --------- Co-authored-by: Hongyu Yao <hongyuyao@hongyus-mbp-3.lan> Co-authored-by: Masen Furer <m_github@0x26.net> Co-authored-by: Hongyu Yao <hongyuyao@Hongyus-MacBook-Pro-3.local>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import numpy as np
|
|
import plotly.graph_objects as go
|
|
import pytest
|
|
|
|
import reflex as rx
|
|
from reflex.utils.serializers import serialize, serialize_figure
|
|
|
|
|
|
@pytest.fixture
|
|
def plotly_fig() -> go.Figure:
|
|
"""Get a plotly figure.
|
|
|
|
Returns:
|
|
A random plotly figure.
|
|
"""
|
|
# Generate random data.
|
|
data = np.random.randint(0, 10, size=(10, 4))
|
|
trace = go.Scatter(
|
|
x=list(range(len(data))), y=data[:, 0], mode="lines", name="Trace 1"
|
|
)
|
|
|
|
# Create a graph.
|
|
return go.Figure(data=[trace])
|
|
|
|
|
|
def test_serialize_plotly(plotly_fig: go.Figure):
|
|
"""Test that serializing a plotly figure works.
|
|
|
|
Args:
|
|
plotly_fig: The figure to serialize.
|
|
"""
|
|
value = serialize(plotly_fig)
|
|
assert isinstance(value, dict)
|
|
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})
|