Skip to main content

Reflex custom component to render graph

Project description

Altair

A Reflex custom component for altair charts.

Installation

pip install reflex-altair

Altair Component

The Altair component is a React component that integrates with the react-vega library to render Vega and Vega-Lite visualizations in your application. This component allows you to specify the chart specifications, data, and various configuration options to customize the rendering and behavior of the visualizations.

It supports altair python library !

Props

spec

  • Type: AltairChart | Dict[str, Any]
  • Description: The Vega or Vega-Lite chart specification. This can be an instance of AltairChart or a dictionary representing the chart specification.

data

  • Type: Dict[str, List[Dict[str, Any]]]
  • Description: The data to be used in the chart. This should be a dictionary where the keys are dataset names and the values are lists of observations.

Transform your dataframe like this

df.to_dict("records")

on_error

  • Type: rx.EventHandler[lambda _e: [_e]]
  • Description: Event handler that is triggered when an error occurs during the rendering of the chart.

mode

  • Type: "vega" | "vega-lite"
  • Description: The mode in which the chart should be rendered. This can be used to specify whether the chart should be rendered in vega or vega-lite mode.

actions

  • Type: bool | AltairAction
  • Description: Configuration for the action menu that appears in the top-right corner of the chart. This can be a boolean to enable/disable the menu or an AltairAction object to customize the actions.

download_file_name

  • Type: str
  • Description: The default file name to use when downloading the chart as an image.

log_level

  • Type: 0 - 5
  • Description: The log level for the Vega parser. This can be used to control the verbosity of the logging output.

renderer

  • Type: AltairRenderer
  • Description: The renderer to use for the chart. This can be set to canvas or svg.

tooltip

  • Type: bool
  • Description: Boolean flag to enable or disable tooltips in the chart.

False overwrite tooltips from spec

padding

  • Type: Union[int, float] | Dict[AltairPadding, Union[int, float]]]
  • Description: Padding around the chart. This can be a single value applied to all sides or a dictionary specifying different padding values for each side. Values are left, right, bottom, left

used instead of default style padding

Events

on_new_view depends on :

  • on_new_view_click
  • on_new_view_dblclick
  • on_new_view_dragenter
  • on_new_view_dragleave
  • on_new_view_dragover
  • on_new_view_keydown
  • on_new_view_keypress
  • on_new_view_keyup
  • on_new_view_mousedown
  • on_new_view_mousemove
  • on_new_view_mouseout
  • on_new_view_mouseover
  • on_new_view_mouseup
  • on_new_view_mousewheel
  • on_new_view_touchend
  • on_new_view_touchmove
  • on_new_view_touchstart
  • on_new_view_wheel

Chart is rerender after an event, removing current selection

signal_listenersis not yet supported

Example Usage

With altair

import altair as alt
import pandas as pd

# Define the data
chart_data = {
    "dataset_id": pd.DataFrame(
        {
            "category": ["A", "B", "C"],
            "value": [28, 55, 43]
        }
    ).to_dict("records")
}

# Define the chart
chart_spec = alt.Chart(alt.Data(name="dataset_id")).mark_bar().encode(
    x='category:O',
    y='value:Q',
    tooltip=['category', 'value']
).properties(
    title='Bar Chart Example'
)

With vega-lite

chart_spec = {
    "data": {"name": "table"},
    "mark": "bar",
    "encoding": {
        "x": {"field": "category", "type": "nominal"},
        "y": {"field": "value", "type": "quantitative"}
    }
}

chart_data = {
    "table": [
        {"category": "A", "value": 28},
        {"category": "B", "value": 55},
        {"category": "C", "value": 43}
    ]
}
# Create the altair component
altair_component = altair_chart(
    spec=chart_spec,
    data=chart_data,
    actions={"export": {"svg": False}, "compiled": False},
    download_file_name="filename",
)

You can run reflex demo also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reflex_altair-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reflex_altair-0.0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file reflex_altair-0.0.1.tar.gz.

File metadata

  • Download URL: reflex_altair-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.10

File hashes

Hashes for reflex_altair-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4e6729b072630b69fd95d70c721a967415185fa3519e7ef0e4ea738b6664410e
MD5 83b107b8e61240a966ecf65d90cc232f
BLAKE2b-256 582c59158107fd219e031967aeb1031a855d34437f191db054baee2402797960

See more details on using hashes here.

File details

Details for the file reflex_altair-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: reflex_altair-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.10

File hashes

Hashes for reflex_altair-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a107d1d93cc27165002d40b02b7c18d6880f5f473e01befca2ad43ebd85f73a6
MD5 a4f8edf30d80e336ccce6183b9d1d168
BLAKE2b-256 3062ab09352d5dd357262fb02bf75b12832731f0c8fef211ab8d7c5c1afdff14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page