I am trying to make a dataframe with clickable value using applymap()
function. I already have it working using .format
which is not what I'd prefer to be using.
data = [dict(name='Google', url='http://www.google.com'),
dict(name='Stackoverflow', url='http://stackoverflow.com')]
df = pd.DataFrame(data)
df['nameurl'] = df['name'] + '#' + df['url']
def make_clickable_both(val):
name, url = val.split('#')
return f'<a target="_blank" href="{url}">{name}</a>'
df.style.format({'nameurl': make_clickable_both})
However, using applymap()
it does not seem to return html code and clickable link as I expected:
df.style.applymap(make_clickable_both, subset=['nameurl'])
ADDED
The reason I'm trying not to use .format is because I'm trying to implement it in streamlit.
Suggestion by @Henry Ecker seems (#3 in the code)to work in jupyter notebook, but does not generate clickable cell values in streamlit as shown below.
# 1
st.dataframe(df.style.applymap(make_clickable_both, subset=['nameurl']))
# 2
st.dataframe(df.style.format({'nameurl': make_clickable_both}))
# 3
df['nameurl'] = df['nameurl'].apply(make_clickable_both)
st.dataframe(df.style)