【发布时间】:2021-05-03 23:20:41
【问题描述】:
大家好,我正在尝试为我的爬虫应用程序构建一个界面,但我很难将用户输入传递给一个变量不是 JSON 可序列化的。我也收到此回调错误:
引发异常。InvalidCallbackReturnValue( dash.exceptions.InvalidCallbackReturnValue:
<Outputoutput-submit.children>的回调 返回类型为tuple的值 这不是 JSON 可序列化的。 有问题的值是唯一返回的值, 或在返回列表的顶层, 并具有字符串表示(<function CSV at 0x11e00a430>, <function pages at 0x104cf4160>, <function url at 0x11e004550>)一般来说,Dash 属性只能是 破折号组件,字符串,字典,数字,无, 或这些列表。
如果您愿意,这是我的代码!我很感激能得到任何帮助。
app.layout = html.Div([
html.Div(
html.Header(
html.H1("Price Scraper")
)
),
html.Div(children=[
html.Label(' address:'),
dcc.Input(
id='input-url',
placeholder='Input Address',
type="text",
style={"width": "25%"}
),
html.Div(id='output-url'),
# ____________________________#
html.Label('How many pages to scrape:'),
dcc.Input(
id='input-pages',
placeholder='Input or choose pages to scrape',
type="number",
min="0"
),
html.Div(id='output-pages'),
# -----------------------------#
html.Label('CSV Filename:'),
dcc.Input(
id='input-csv',
placeholder='Input filename ending in .csv',
type="text"
),
html.Div(id='output-csv'),
# ------------------------------#
html.Button('submit',
id='input-submit'),
html.Div(id='output-submit',
children='Click the button to run program'),
]),
])
@app.callback(
Output(component_id='output-url', component_property='children'),
[Input(component_id='input-url', component_property='value')]
)
def url(input_value):
url = str(input_value)
# ---------------#
@app.callback(
Output(component_id='output-pages', component_property='children'),
[Input(component_id='input-pages', component_property='value')]
)
def pages(input_value):
pages = str(input_value)
# ---------------#
@app.callback(
Output(component_id='output-csv', component_property='children'),
[Input(component_id='input-csv', component_property='value')]
)
def CSV(input_value):
CSV = str(input_value)
#---------------#
@app.callback(
Output(component_id='output-submit', component_property='children'),
[Input(component_id='input-submit', component_property='n_clicks')]
)
def run_script(n_clicks):
if n_clicks:
print(CSV, pages, url)
# ---------------#
if __name__ == "__main__":
app.run(debug=True)
【问题讨论】:
-
您正在尝试打印 CSV、页面、网址,这些都是函数。我猜这不是故意的?
标签: json python-3.x plotly-dash