ใน plotly วิ่งแอพฉันเพิ่มเป็นข้อความหมายเหตุประกอบ annotation tool กับ clickable เชื่อมต่อนั้นมีค่อยจัดการเรื่องอยู่ในนั้น
topic = "Australia" # might contain spaces
hashtag = "#" + topic
annotation_text=f"<a href=\"https://twitter.com/search?q={urllib.parse.quote_plus(hashtag)}&src=typed_query&f=live\">{topic}</a>"
ฉันต้องการแสดงผล html ที่จะควบคุม "https://twitter.com/search?q=%23Australia&src=typed_query&f=live"
แต่ฉันไม่สามารถได้"#"ตัวละครเพื่อทำการเข้ารหัสอย่างเหมาะสม มันจะส encoded ไปยัง%2523.
ขนาดเล็กที่สุดทำงานตัวอย่าง:
import dash
from dash.dependencies import Input, Output
import plotly.express as px
import urllib.parse
df = px.data.gapminder()
all_continents = df.continent.unique()
app = dash.Dash(__name__)
app.layout = dash.html.Div([
dash.dcc.Checklist(
id="checklist",
options=[{"label": x, "value": x}
for x in all_continents],
value=all_continents[4:],
labelStyle={'display': 'inline-block'}
),
dash.dcc.Graph(id="line-chart"),
])
@app.callback(
Output("line-chart", "figure"),
[Input("checklist", "value")])
def update_line_chart(continents):
mask = df.continent.isin(continents)
fig = px.line(df[mask],
x="year", y="lifeExp", color='country')
annotations = []
df_last_value = df[mask].sort_values(['country', 'year', ]).drop_duplicates('country', keep='last')
for topic, year, last_lifeExp_value in zip(df_last_value.country, df_last_value.year, df_last_value.lifeExp):
hashtag = "#" + topic
annotations.append(dict(xref='paper', x=0.95, y=last_lifeExp_value,
xanchor='left', yanchor='middle',
text=f"<a href=\"https://twitter.com/search?q={urllib.parse.quote_plus(hashtag)}&src=typed_query&f=live\">{topic}</a>",
# text=f"<a href=\"https://twitter.com/search?q=#{urllib.parse.quote_plus(topic)}&src=typed_query&f=live\">{topic}</a>",
font=dict(family='Arial',
size=16),
showarrow=False))
fig.update_layout(annotations=annotations)
return fig
app.run_server(debug=True)
ตอนที่คุณวิ่งนี้แล้วคลิกที่ปุ่มข้อความ"ออสเตรเลีย"ตอนจบของเส้นกราฟ,มันควรจะเปิดขึ้นมาเป็นทวิตเตอร์ค้นหาหน้าสำหรับ#ออสเตรเลีย
สิ่งที่ฉันพยายาม:
- แค่ใช้เปลือย"#"อักขระ:
text=f"<a href=\"https://twitter.com/search?q=#{urllib.parse.quote_plus(topic)}&src=typed_query&f=live\">{topic}</a>"
ที่นี่#ตัวละครยังไม่ encoded เป็น%23 ในการส่งออกซึ่งผลตรวจในหักเชื่อมโยงเพื่อนของทวิตเตอร์
https://twitter.com/search?q=#mytopic&src=typed_query&f=live
เชื่อมโยง
- ใช้ quote_plus อยู่ด้วยแท็ก
text=f"<a href=\"https://twitter.com/search?q=#{urllib.parse.quote_plus(hashtag)}&src=typed_query&f=live\">{topic}</a>"
ที่นี่%23(การเข้ารหัส#คน)จะได้ encoded อีกครั้งผลลัพธ์จากใน%2523 อยู่ในส่วนส่งออก
https://twitter.com/search?q=%2523mytopic&src=typed_query&f=live
เชื่อมโยง
แล้วฉันจะทำยังไงให้ได้มันต้องอย่างถูกต้องทำการเข้ารหัสที่#(เป็น%23)ดังนั้นฉันเข้าใจ
href="https://twitter.com/search?q=%23mytopic&src=typed_query&f=live