gpt4 book ai didi

python - 我正在尝试在 dash 应用程序中单击按钮重定向到另一个页面,但它不起作用

转载 作者:行者123 更新时间:2023-12-04 14:54:44 40 4
gpt4 key购买 nike

import datetime
import sqlite3
import webbrowser
from time import sleep
import dash
import dash_html_components as html
import dash_core_components as dcc

from flask import Response

app = dash.Dash()
server = app.server

app.layout = html.Div([html.H1('Graphs will be added here'),
html.P('click on LOG_VIEW to view logger'),
dcc.Link(
html.Button('LOG_VIEW'),
href='/log_stream')])

latest_sno = 0

def flask_logger():
"""creates logging information"""
global latest_sno, data
values = ''
connection = sqlite3.connect(r'C:\Users\rohit\Desktop\newbase.db')
s = ''
while True:
try:
data = connection.cursor()
pt = data.execute(f"Select * FROM cvt WHERE SNO >{latest_sno}")
values = pt.fetchall()
except sqlite3.Error as e:
pass
finally:
latest_sno = int(
data.execute("SELECT SNO FROM cvt ORDER BY SNO DESC LIMIT 1").fetchall().__getitem__(0).__getitem__(0))
current_time = datetime.datetime.now().strftime('%H:%M:%S')
y = ['name','Address','age','id']
if(len(values)!=0):
for i in values:
s = s + '\n' + str(dict(zip(y, i))) + '\n'

current_time = '\n'+current_time+s
yield current_time.encode()
s = ''
sleep(0.24)


@server.route("/log_stream", methods=["GET"])
def stream():
return Response(flask_logger(), mimetype="text/plain", content_type="text/event-stream")


if __name__ == '__main__':
app.run_server(debug=True)
webbrowser.open('http://127.0.0.1:8050/')

我在 python 中使用破折号,我想重定向到位置“\log_stream”。以上是我尝试实现的方式,页面没有被重定向,但 URL 发生了变化。我哪里出错了或关于如何做的任何建议。任何帮助将不胜感激 提前致谢。

这是我关注的链接 https://github.com/plotly/dash-core-components/issues/189#issuecomment-383228871

最佳答案

这里需要刷新。

您可以将 Linkrefresh 属性设置为 True:

dcc.Link(html.Button("LOG_VIEW"), href="/log_stream", refresh=True),

refresh (boolean; default False): Controls whether or not the page will refresh when the link is clicked.

https://dash.plotly.com/dash-core-components/link

关于python - 我正在尝试在 dash 应用程序中单击按钮重定向到另一个页面,但它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68290267/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com