Giter Club home page Giter Club logo

dash-ui's Introduction

dash-ui

Grid

Grid makes use of the CSS grid to make creating dashboard-like layouts super easy in Dash.

ControlPanel

ControlPanel adds a panel to the side of the grid which contains input components to change the state of the plot grid.

A Simple Example Grid

This example is found in simple_demo.py image

First we add the external css url https://codepen.io/rmarren1/pen/mLqGRg.css. This is necessary for the grid to work. If you cannot use this (e.g. you are serving stylesheets locally) you can just serve the file at https://github.com/rmarren1/dash-ui/blob/master/dash_ui/style/css/grid.css .

Next, we create a grid with the following call: grid = dui.Grid(_id="grid", num_rows=12, num_cols=12, grid_padding=5)

  • num_rows is the number of rows in the grid, and must be between 1 and 12
  • num_cols is the number of columns in the grid, and must be between 1 and 12
  • grid_padding is the number of pixels to pad between grid elements, and must be one of [0, 1, 2, 5, 10, 25, 50, 100].

Now you can add any dash element as a grid element like so:

grid.add_element(col=1, row=1, width=3, height=4, element=html.Div(
    style={"background-color": "red", "height": "100%", "width": "100%"}
))
  • row is the starting row in the grid layout
  • col is the starting column in the grid layout
  • height is the number of rows the element should span.
  • width is the number of columns the element should span

Note that the rows and columns are one indexed.

Finally, we create the layout using the function dui.Layout(grid=grid,)

and set app.layout as the object this function returns.

A Grid with ControlPanel

This example shows the grid with real plots (see advanced_demo.py) image

If a ControlPanel is not included, the grid will take up the entire screen. To include the ControlPanel, create one using code like the following:

controlpanel = dui.ControlPanel(_id="controlpanel")
controlpanel.create_group(
    group="State",
    group_title="Change the selected State."
)
state_select = dcc.Dropdown(
    id="state-dropdown",
    options=[{
        'label': x.title(),
        'value': x
        } for x in df["state"].tolist()
    ],
    value=df["state"].tolist()[0]
)
controlpanel.add_element(state_select, "State")

then include the controlpanel instance as an argument to the dui.Layout function, e.g.

app.layout = dui.Layout(
    grid=grid,
    controlpanel=controlpanel
)

We can also add plotly graph elements with the shortcut grid.add_graph(col=1, row=1, width=3, height=4, graph_id="all-pie") which creates a grid element with a graph with the id declared in graph_id.

We can end up with this really nice interactive dashboard, with only 200 lines of code.

Customizing the style

To have your own flavor of dashboard, simply fork the source SASS here, make changes, then add the css from codepen to your project using:

my_css_urls = [
  "https://codepen.io/your-codepen-name/pen/your-pen-identifier.css",
]

for url in my_css_urls:
    app.css.append_css({
        "external_url": url
    })

dash-ui's People

Contributors

rmarren1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.