gt-extras
  • Get Started
  • API Reference
  1. HTML Helpers
  2. gt_hyperlink
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
    • gt_plt_conf_int
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  1. HTML Helpers
  2. gt_hyperlink

gt_hyperlink

gt_hyperlink(text, url, new_tab=True)

Create HTML hyperlinks for use in GT object cells.

The gt_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.

Examples

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.gt_hyperlink(name, url)
    for name, url in zip(df["name"], df["url"])
]

df["Github Stars"] = [
    gte.gt_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"]])
Package Github Stars
Great Tables 2334
Plotnine 4256
Quarto 4628
gt_fa_rating
with_tooltip