search
HomeBackend DevelopmentPython TutorialPython uses Dash to develop web applications

Python uses Dash to develop web applications

Control basis for developing web applications with Python Dash

This article mainly uses Dash’s Checklist component to briefly introduce web applications developed using Dash

The display effect is as follows:

Python uses Dash to develop web applications

python dash simple basics

The Dash application consists of two parts:

  • The first part is the layout of the application (Layout), which describes the appearance of the application.
  • The second part describes the interactivity of the application.

1. Dash layout Layout

The layout of the Dash application describes the appearance of the application. The layout is a hierarchical tree of components.

Dash HTML Components (dash.html) provides classes for all HTML tags and HTML attribute keyword parameter descriptions, such as style, class and id.

Dash core components (dash .dcc) generate high-level components such as controls and graphics.

Dash Layout has several features:

  • The layout consists of a component tree.
  • Create complex reusable components.
  • Core component module dash .dcc contains a component called Graph, which uses the open source plotly.js JavaScript graphics library to present interactive data visualizations. js supports more than 35 chart types and renders charts with vector-quality SVG and high-performance WebGL. For details, please refer to: plotly.py documentation and gallery.
  • For writing text blocks, you can use the Markdown component in dash.dcc.
  • Dash core components (dash.dcc) include a set of higher-level components, such as drop-down menus, graphics, marker blocks, etc.

1. Dash’s HTML component

Dash is a web application framework that provides pure Python abstractions around HTML, CSS, and JavaScript. Instead of writing HTML or using an HTML template engine, compose layouts using Python and the Dash HTML Components module.

Dash HTML component module is part of Dash and can be found at https://github.com/plotly/dash Find its source code.

2. Dash’s Core component

Dash is equipped with dynamic components for interactive user interfaces.

The Dash Core Components module can be imported and used via from dash import dcc and allows access to many interactive components, including drop-down menus, checklists, and sliders .

The dcc module is part of Dash and can be found at https://github.com/plotly/dash Find its source code.

2. Checklist in Dash Core

dcc.Checklist is a component used to present a set of check boxes.

Let's use the Checklist control to set up a simple project to illustrate some simple content of developing Web applications with Dash

The directory structure of Demo is as follows :

.
└── dash_demo
├── app.py
└── assets
├── favicon.ico
└── img
├── julia_50px_icon.png
├── python_50px_icon.png
└── r_50px_icon.png

The content of app.py is as follows:

from dash import Dash, html, dcc
app = Dash(__name__)
app.title = 'Dash控件教程'
app.layout = html.Div(children=[
dcc.Checklist(
options=['Python语言', 'Julia语言', 'R语言'],
value=['Python语言', 'R语言']
),
dcc.Checklist(
options=[
{'label': 'Python语言', 'value': '1'},
{'label': 'Julia语言', 'value': '2'},
{'label': 'R语言', 'value': '3'},
],
value=['1', '3']
),
dcc.Checklist(
options={
'1': 'Python语言',
'2': 'Julia语言',
'3': 'R语言',
},
value=['1', '3']
),
dcc.Checklist(
options=[
{
'label': html.Img(src=app.get_asset_url('img/python_50px_icon.png')),
'value': 'Python语言',
},
{
'label': html.Img(src=app.get_asset_url('img/julia_50px_icon.png')),
'value': 'Julia语言',
},
{
'label': html.Img(src=app.get_asset_url('img/r_50px_icon.png')),
'value': 'R语言',
},
],
value=['Python语言', 'R语言']
),
])

if __name__ == '__main__':
app.run_server(debug=True)

Run the project: python app.py.

Browser access: http://127.0.0.1:8050.

Python uses Dash to develop web applications

Dash Demo

Simple description:

  • assets directory is officially recommended for storing our Dash application Directory of dependent static resource files, such as dependent static resources such as css, js, favicon.ico, various images and fonts.
  • Dash control has many forms of use and is very flexible. For example, in the Checklist in the article, the label of the option (seen by the user) and the value (passed to the callback) are equivalent. When used, we prefer to keep them separate so that the label can be easily changed without changing the callback logic that uses the value.

The above is the detailed content of Python uses Dash to develop web applications. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
详细讲解Python之Seaborn(数据可视化)详细讲解Python之Seaborn(数据可视化)Apr 21, 2022 pm 06:08 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

详细了解Python进程池与进程锁详细了解Python进程池与进程锁May 10, 2022 pm 06:11 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

Python自动化实践之筛选简历Python自动化实践之筛选简历Jun 07, 2022 pm 06:59 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

归纳总结Python标准库归纳总结Python标准库May 03, 2022 am 09:00 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于标准库总结的相关问题,下面一起来看一下,希望对大家有帮助。

分享10款高效的VSCode插件,总有一款能够惊艳到你!!分享10款高效的VSCode插件,总有一款能够惊艳到你!!Mar 09, 2021 am 10:15 AM

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

python中文是什么意思python中文是什么意思Jun 24, 2019 pm 02:22 PM

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。

Python数据类型详解之字符串、数字Python数据类型详解之字符串、数字Apr 27, 2022 pm 07:27 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

详细介绍python的numpy模块详细介绍python的numpy模块May 19, 2022 am 11:43 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function