में एक plotly पानी का छींटा अनुप्रयोग, मैं जोड़ रहा हूँ एक पाठ एनोटेशन एक क्लिक करने योग्य लिंक है कि एक हैश है ।
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"
लेकिन मैं नहीं मिल सकता है "#" चरित्र सांकेतिक शब्दों में बदलना करने के लिए ठीक से. यह हो जाता है डबल करने के लिए इनकोडिंग %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>"
यहाँ, # चरित्र नहीं है के रूप में इनकोडिंग %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 (इनकोडिंग # चरित्र) हो जाता है इनकोडिंग फिर, जिसके परिणामस्वरूप %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