import pandas as pd
from great_tables import GT
import gt_extras as gte
df = pd.DataFrame(
{
"name": ["Great Tables", "Plotnine", "Quarto"],
"url": [
"https://posit-dev.github.io/great-tables/",
"https://plotnine.org/",
"https://quarto.org/",
],
"github_stars": [2334, 4256, 4628],
"repo_url": [
"https://github.com/posit-dev/great-tables",
"https://github.com/has2k1/plotnine",
"https://github.com/quarto-dev/quarto-cli",
],
}
)
df["Package"] = [
gte.with_hyperlink(name, url)
for name, url in zip(df["name"], df["url"])
]
df["Github Stars"] = [
gte.with_hyperlink(github_stars, repo_url, new_tab=False)
for github_stars, repo_url in zip(df["github_stars"], df["repo_url"])
]
GT(df[["Package", "Github Stars"]])with_hyperlink
with_hyperlink(text, url, new_tab=True)Create HTML hyperlinks for use in GT cells.
The with_hyperlink() function creates properly formatted HTML hyperlink elements that can be used within table cells.
Parameters
text : str-
A string that will be displayed as the clickable link text.
url : str-
A string indicating the destination URL for the hyperlink.
new_tab : bool = True-
A boolean indicating whether the link should open in a new browser tab or the current tab.
Returns
: str-
An string containing the HTML formatted hyperlink element.