';儿童';Python html中的属性
我对“孩子们”在html中的行为感到困惑。它为什么会存在?你为什么要用它?我试着阅读文档,但没有多大帮助 关于下面的代码块:';儿童';Python html中的属性,python,plotly-dash,Python,Plotly Dash,我对“孩子们”在html中的行为感到困惑。它为什么会存在?你为什么要用它?我试着阅读文档,但没有多大帮助 关于下面的代码块: 儿童财产在第一行中做了什么 你不能用“人物”之类的东西来代替孩子们吗 代码块: app.layout = html.Div(children=[ # TODO1: Add title to the dashboard html.H1("Airline Dashboard by CK", style = {'text-align':'
- 儿童财产在第一行中做了什么
- 你不能用“人物”之类的东西来代替孩子们吗
app.layout = html.Div(children=[
# TODO1: Add title to the dashboard
html.H1("Airline Dashboard by CK", style = {'text-align':'center'}),
# REVIEW2: Dropdown creation
# Create an outer division
html.Div([
# Add an division
html.Div([
# Create an division for adding dropdown helper text for report type
html.Div(
[
html.H2('Report Type:', style={'margin-right': '2em'}),
]
),
# TODO2: Add a dropdown
dcc.Dropdown(id = 'input-type',
options = [{'label':'Yearly Airline Performance Report', 'value': 'OPT1'},
{'label':'Yearly Average Flight Delay Statistics', 'value': 'OPT2'}],
multi = False,
placeholder = 'Select a Report Type',
style={'width': '80%', 'padding': '3px', 'font-size': '20px', 'text-align-last': 'center'}
)
# Place them next to each other using the division style
], style={'display': 'flex'}),
# Add next division
html.Div([
# Create an division for adding dropdown helper text for choosing year
html.Div(
[
html.H2('Choose Year:', style={'margin-right': '2em'})
]
),
dcc.Dropdown(id='input-year',
# Update dropdown values using list comphrehension
options=[{'label': i, 'value': i} for i in year_list],
placeholder="Select a year",
style={'width': '80%', 'padding': '3px', 'font-size': '20px', 'text-align-last': 'center'}),
# Place them next to each other using the division style
], style={'display': 'flex'}),
]),
# Add Computed graphs
# REVIEW3: Observe how we add an empty division and providing an id that will be updated during callback
html.Div([], id='plot1'),
html.Div([
html.Div([], id='plot2'),
html.Div([], id='plot3')
], style={'display': 'flex'}),
# TODO3: Add a division with two empty divisions inside. See above disvision for example.
html.Div([
html.Div([], id='plot4'),
html.Div([], id='plot5')
], style = {'display':'flex'})
])
# Callback function definition
# TODO4: Add 5 ouput components
@app.callback(
[Input(component_id='input-type', component_property='value'),
Input(component_id='input-year', component_property='value')],
# REVIEW4: Holding output state till user enters all the form information. In this case, it will be chart type and year
[Output("plot1", 'children'), Output("plot2", "children"),
Output("plot3", "children"), Output("plot4", "children"),
Output("plot5", "children")
])
从下列文件中:
html.Div
和html.p
,接受其子项的值。其他,如dcc.Graph
或dcc.Dropdown
则不需要,需要其他道具才能正常工作
正如@KarlKnechtel在他的评论中提到的,当一个组件是另一个组件的子组件时,它表示第一个组件嵌套在另一个组件中。以下是类似的:
破折号:
html.Div(
孩子们=[
H1('这是一些文本'),
html.P('这也是一些文本'),
]
)
在HTML中:
这是一些文本
这也是一些文字
我希望这能回答你的问题
编辑:
在children
之后添加style
到该html.Div
将允许您更改Div
的样式,这可能会影响嵌套在其中的组件的样式,但这不是children
属性的目的。正如文档中提到的,您可以显式地设置children=
任何内容,也可以先传递相同的值,而不使用显式的关键字参数,Dash将把它视为children
属性。无论哪种方式,在幕后,组件仍在接收其子属性的值
children
属性的目的是允许用户嵌套组件,就像我们在原始HTML中所做的那样。如果没有子项
道具,就不可能通过将相关项目包含在同一父元素中(例如,将导航项目放在顶部导航栏中)来将它们分组在一起。来自以下文档:
儿童财产是特殊的。按照惯例,它总是第一个属性,这意味着您可以忽略它:html.H1(children='Hello-Dash')与html.H1('Hello-Dash')相同。此外,它还可以包含字符串、数字、单个组件或组件列表
某些组件,例如html.Div
和html.p
,接受其子项的值。其他,如dcc.Graph
或dcc.Dropdown
则不需要,需要其他道具才能正常工作
正如@KarlKnechtel在他的评论中提到的,当一个组件是另一个组件的子组件时,它表示第一个组件嵌套在另一个组件中。以下是类似的:
破折号:
html.Div(
孩子们=[
H1('这是一些文本'),
html.P('这也是一些文本'),
]
)
在HTML中:
这是一些文本
这也是一些文字
我希望这能回答你的问题
编辑:
在children
之后添加style
到该html.Div
将允许您更改Div
的样式,这可能会影响嵌套在其中的组件的样式,但这不是children
属性的目的。正如文档中提到的,您可以显式地设置children=
任何内容,也可以先传递相同的值,而不使用显式的关键字参数,Dash将把它视为children
属性。无论哪种方式,在幕后,组件仍在接收其子属性的值
children
属性的目的是允许用户嵌套组件,就像我们在原始HTML中所做的那样。如果没有子项
道具,就不可能通过将相关项包含在同一父元素中(例如,将导航项放在顶部导航栏中)来将它们分组在一起。“我尝试阅读文档,但没有多大帮助。”具体来说,您看了哪些文档?您在其中发现了哪些提到儿童的文本,以及您发现哪些内容令人困惑或缺乏信息?看起来您正在使用一个以某种方式表示HTML的库。你知道HTML是什么样子吗?你明白一个HTML标记是另一个的孩子意味着什么吗?@KarlKnechtel这就是我所看到的:基本上,它似乎说任何东西都不需要它?如果是这样的话,为什么还要放在那里?它到底应该做什么?“我试着阅读文档,但没有太大帮助。”具体来说,你看了哪些文档?您在其中发现了哪些提到儿童的文本,以及您发现哪些内容令人困惑或缺乏信息?看起来您正在使用一个以某种方式表示HTML的库。你知道HTML是什么样子吗?你明白一个HTML标记是另一个的孩子意味着什么吗?@KarlKnechtel这就是我所看到的:基本上,它似乎说任何东西都不需要它?如果是这样的话,为什么还要放在那里?它到底应该做什么?有趣的是,如果在代码中的children之后添加样式,它会对div中的所有内容进行样式化吗?这就是children=[]的目的吗?我在回答这个问题时添加了一个带有更多解释的编辑。谢谢!这很有帮助:)很有趣,所以如果在代码中的子级之后添加样式,