这个是实例的代码, 后面的代码里面有
import dash_html_components as html
html.Div, html.Table
这些东西, 然后我搜索了一下找到了 dash_html_components 这个文件夹, 但是文件夹是这样的, 没有看到 Table 或者 Div 这样的定义,这个问题是怎么处理的?
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/[email protected]{}"
"/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)