达世币应用程序 | f 字符串回调输出不会显示在新行上 (' ')

问题描述 投票:0回答:1

当我创建以下破折号应用程序时,目标是将回调显示的输出中包含的每个元素显示在新行上。但是,当我运行该应用程序时,每个元素都显示在同一行上。当前输出与所需输出的图像嵌入在代码片段之后。

请分享解决方案并解释为什么我的代码没有提供所需的结果:

app = Dash(__name__)

app.layout = html.Div([
    dcc.Dropdown(
        id = 'dd_input', 
        options = ['test1', 'test2', 'test3'], 
        value = ['test1', 'test2'],
        multi = True
        ),
    html.P(
        id = 'string_output'
        ) 
])

@callback(
    Output('string_output', 'children'), 
    Input('dd_input','value')
)

def test_func(dd_choice):
    string = ''
    new_line = '\n'
    
    for each in dd_choice:
        string += f'{each}{new_line}'
        
    return string
                       
if __name__ == '__main__':
    app.run(debug = True)

这是我不断得到但我不想要的输出:

以下是所需的输出:

尝试使用追加和连接方法:

python html plotly-dash f-string
1个回答
0
投票

就像 Barmar 所说,你需要使用

<br>
来换行。 尝试使用这个:

...
from dash import html
...
for each in dd_choice:
    string.append(each)
return html.Br().join(string)
...

来源:https://dash.plotly.com/dash-html-components/br

© www.soinside.com 2019 - 2024. All rights reserved.