V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

阅读 Python dash 代码的时候有个问题, 那个包的调用有问题?

  •  
  •   woshichuanqilz · 2017-12-15 11:16:31 +08:00 · 2157 次点击
    这是一个创建于 2570 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个是实例的代码, 后面的代码里面有 import dash_html_components as html

    html.Div, html.Table

    这些东西, 然后我搜索了一下找到了 dash_html_components 这个文件夹, 但是文件夹是这样的, 没有看到 Table 或者 Div 这样的定义,这个问题是怎么处理的?

    20171215111403

    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    
    import pandas as pd
    
    df = pd.read_csv(
        'https://gist.githubusercontent.com/chriddyp/'
        'c78bf172206ce24f77d6363a2d754b59/raw/'
        'c353e8ef842413cae56ae3920b8fd78468aa4cb2/'
        'usa-agricultural-exports-2011.csv')
    
    
    def generate_table(dataframe, max_rows=10):
        return html.Table(
            # Header
            [html.Tr([html.Th(col) for col in dataframe.columns])] +
    
            # Body
            [html.Tr([
                html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
            ]) for i in range(min(len(dataframe), max_rows))]
        )
    
    
    app = dash.Dash()
    
    app.layout = html.Div(children=[
        html.H4(children='US Agriculture Exports (2011)'),
        generate_table(df),
        dcc.Interval(
                    id='interval-component',
                    interval=1*1000, # in milliseconds
                    n_interval=0
                )
    ])
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    

    我看了一下 init.py 的定义, 是不是把那些定义都写到 js 文件里面了。

    import os as _os import dash as _dash import sys as _sys from .version import version

    _current_path = _os.path.dirname(_os.path.abspath(file))

    _components = _dash.development.component_loader.load_components( _os.path.join(_current_path, 'metadata.json'), 'dash_html_components' )

    _this_module = _sys.modules[name]

    _js_dist = [{ "relative_package_path": "bundle.js", "external_url": ( "https://unpkg.com/dash-html-components@{}" "/dash_html_components/bundle.js" ).format(version), "namespace": "dash_html_components" }]

    for component in _components: setattr(_this_module, component.name, component) setattr(component, '_js_dist', _js_dist)

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2602 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:23 · PVG 13:23 · LAX 21:23 · JFK 00:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.