人生苦短,早用Python!
相信大家都用过Navicat,Sqlyog,癞蛤蟆之类的数据库可视化工具。那么,自己能不能做一个类似的数据库可视化的东西呢,毕竟原生的命令行不是很美观,Python50行代码搞定!
先上效果图:
0.导入相关依赖库
缺少相关模块,自行下载即可,下载命令: pip install xxx
import dash
import dash_html_components as html
import dash_bootstrap_components as dbc
import dash_core_components as dcc
from dash.dependencies import Input, Output, State
import pandas as pd
from sqlalchemy import create_engine
1.编写数据库配置信息
以关系型数据库Postgresql数据库为例,当然也可以使用其他数据库!
postgres_url = 'postgresql://postgres:root@localhost:5432/db1'
engine = create_engine(postgres_url)
2.创建Dash对象
app = dash.Dash(__name__)
3.设置页面布局
页面布局使用了bootstrap的网格布局,两行,第一行:两个按钮,一个下拉框,第二行:留白部分,显示查询的表信息!
app.layout = html.Div(
dbc.Container(