Dash DAQ

repository·master·Indexed 40 days ago

https://github.com/plotly/dash-daq

Specialized Data Acquisition (DAQ) components for Dash version 0.6.0, designed for industrial and scientific dashboards. Includes components such as Gauge, Knob, LEDDisplay, PowerButton, Indicator, GraduatedBar, and ColorPicker, featuring a themed styling system and advanced color manipulation utilities.

Tokens
13.9K
Snippets
35
Records
51
Agent score
49%

What's inside Dash DAQ

  1. Access Dash DAQ component documentation

    master

    Detailed API documentation for all Dash DAQ components, including available properties and usage instructions, is available at the official Dash documentation site.

    https://dash.plotly.com/dash-daq
  2. Persist Knob values across refreshes

    master

    To ensure that a user's selected value is not lost when the page is refreshed, use the persistence properties. The Knob component supports storing the value in different browser storage mechanisms.

    • persistence: (boolean | string | number) Enables persistence.
    • persistence_type: Defines where the value is stored:
      • 'memory': Kept in memory; reset on page refresh.
      • 'local': Uses window.localStorage; persists even after the browser is closed.
      • 'session': Uses window.sessionStorage; cleared when the browser session ends.
    • persisted_props: An array specifying which props to persist. For the Knob, this is typically ['value'].
  3. Color manipulation utilities in dash-daq

    master

    The library includes a robust color manipulation engine (based on colord) that allows for advanced color transformations. You can create new color instances from various formats and apply modifications.

    Supported Formats

    • HEX: #ffffff, #fff, #ffffff00 (hex8)
    • RGB/RGBA: rgb(255, 255, 255), rgba(255, 255, 255, 1)
    • HSL/HSLA: hsl(360, 100%, 50%)
    • HSV/HSVA: hsv(360, 100%, 100%)
    • Named Colors: aliceblue, antiquewhite, aqua, etc.

    Available Transformations

    • lighten(): Increases lightness.
    • darken(): Decreases lightness.
    • brighten(): Increases brightness.
    • desaturate(): Reduces saturation.
    • saturate(): Increases saturation.
    • greyscale(): Converts to grayscale.
    • spin(degrees): Rotates the hue.
    • complement(): Returns the complementary color.
    • triad(): Returns a triad of colors.
    • analogous(): Returns analogous colors.
    • monochromatic(): Returns monochromatic colors.
    • splitcomplement(): Returns split-complementary colors.
    • tetrad(): Returns tetradic colors.

    Color Utility Methods

    • isDark() / isLight(): Checks brightness levels.
    • getLuminance(): Returns the relative luminance.
    • toRgb(), toHsl(), toHex(), toHsv(): Conversion methods.
    • mix(color1, color2, ratio): Blends two colors.
    // Conceptual usage of color manipulation
    const color = p('#ff0000');
    const lighterColor = color.lighten();
    const complementary = color.complement();
    const mixed = p.mix('#ff0000', '#0000ff', 50); // 50% blend
  4. Configure Slider update modes and state synchronization

    master

    The Slider component provides two primary ways to handle value updates via the updatemode prop:

    1. mouseup (Default): The onChange event is triggered, but the component's internal state or the external Dash state is typically updated only when the interaction ends. This is efficient for preventing excessive callbacks during a drag.

    2. drag: The component updates the value continuously as the user moves the handle. When using this mode, you must provide a setProps function to communicate the intermediate values back to the Dash application, otherwise the slider may appear to jump or reset.

    Props for State Management

    • updatemode: 'mouseup' | 'drag'
    • setProps: A function used to update the component's props from within the component (essential for 'drag' mode).
    • value: The current numeric value of the slider.
    // Example of continuous update using 'drag' mode
    <Slider
      updatemode="drag"
      setProps={({ value }) => {
        // This function is called during the drag to sync the value
        console.log("Current value during drag:", value);
      }}
    />
  5. Configure persistence for NumericInput

    master

    To ensure a user's input is not lost when the page is refreshed, use the persistence and persistence_type props.

    • persistence: Set to True (or a truthy value) to enable persistence.
    • persistence_type:
      • 'local': Uses window.localStorage; data persists even after the browser is closed.
      • 'session': Uses window.sessionStorage; data is cleared when the browser is closed.
      • 'memory': Data is kept in memory and reset on page refresh.
    # Example: Persisting the value in localStorage
    daq_input = dash_daq.NumericInput(
        id='persistent-input',
        value=5,
        persistence=True,
        persistence_type='local'
    )
  6. Understand the Motion component and transition support

    master

    The Motion component (and its internal implementation Hs) provides support for CSS transitions and animations during the lifecycle of a component (appearing, entering, leaving, or disappearing).

    Motion Lifecycle States

    Components using motion support several states:

    • appear: The initial mounting of the component.
    • enter: Transitioning from hidden/non-existent to visible.
    • leave: Transitioning from visible to hidden.
    • none: A neutral state.

    Configuration Props

    • motionName: A string or object defining the CSS class names used for different motion states.
    • visible: Controls whether the component is currently visible.
    • motionAppear, motionEnter, motionLeave: Booleans to enable/disable specific lifecycle animations.
    • removeOnLeave: If true, the component will be removed from the DOM after the leave animation completes.
    • leavedClassName: A CSS class applied to the component once it has finished its leave animation.
    • onAppearStart, onAppearActive, onAppearEnd: Callbacks for the appearance lifecycle.
    • onEnterStart, onEnterActive, onEnterEnd: Callbacks for the enter lifecycle.
    • onLeaveStart, onLeaveActive, onLeaveEnd: Callbacks for the leave lifecycle.
  7. Persist ColorPicker values

    master

    To ensure a user's selected color is preserved after a page refresh, use the persistence and persistence_type properties.

    Available persistence_type options:

    • local: Uses window.localStorage; data persists even after the browser is closed.
    • session: Uses window.sessionStorage; data is cleared when the browser is closed.
    • memory: Data is kept only in memory and is reset on page refresh.
    dash_daq.ColorPicker(
        id='persistent-picker',
        persistence=True,
        persistence_type='local'
    )
  8. How dash-daq components are styled and themed

    master

    Dash DAQ components use a themed styling system. Components are rendered with specific CSS classes following a naming convention: daq-{component_name}--{theme_mode}, where {theme_mode} is either --light or --dark.

    Theme colors are managed via a theme object. The default theme includes:

    • primary: #ABE2FB
    • secondary: #E6E6E6
    • detail: #D3D3D3
    • dark: false (default)

    Users can provide a custom theme object to override these values. If dark: true is set in the theme, components will use the --dark CSS variant.

    // Conceptual representation of the naming convention
    // <div class="daq-component-name--light"></div>
    // <div class="daq-component-name--dark"></div>
  9. Configure dual labels for ToggleSwitch

    master

    To display different labels for the 'on' and 'off' states, pass an array to the label property.

    • If vertical is False: The first element is the left label, and the second is the right label.
    • If vertical is True: The first element is the bottom label, and the second is the top label.

    Labels can be simple strings or objects containing a label string and a style object.

    # Example of dual labels with custom styling
    dash_daq.ToggleSwitch(
        id='dual-label-switch',
        label=[
            {'label': 'OFF', 'style': {'color': 'red'}},
            {'label': 'ON', 'style': {'color': 'green'}}
        ]
    )
  10. Persist ToggleSwitch state

    master

    You can ensure that a user's toggle state is remembered even after a page refresh by using the persistence and persistence_type properties.

    • persistence: Set to True to enable persistence.
    • persistence_type:
      • 'local': Uses window.localStorage (persists after browser close).
      • 'session': Uses window.sessionStorage (cleared when browser is closed).
      • 'memory': Kept only in memory (reset on page refresh).
  11. Configure Gauge scale and labels

    master

    The Gauge component allows fine-grained control over how the scale (ticks and numbers) is rendered via the scale prop.

    scale Prop Options:

    • start: (number) The starting value of the scale.
    • interval: (number) The step size between labels.
    • labelInterval: (number) How many intervals to skip before rendering a label.
    • custom: (object) An object containing custom labels and styles for specific values.

    Label Positioning:

    • labelPosition: Can be set to 'top' or 'bottom' to determine where the main label is placed relative to the gauge.
    <Gauge
      min={0}
      max={100}
      scale={{
        start: 0,
        interval: 10,
        labelInterval: 2,
        custom: {
          50: { label: 'Midpoint', style: { fontWeight: 'bold' } }
        }
      }}
      labelPosition="top"
    />