【问题标题】:Add hyperlink to gt table groupname column in R将超链接添加到 R 中的 gt 表组名列
【发布时间】:2023-01-21 06:35:38
【问题描述】:

我有下表。
我希望 groupname_col(“make”)中的超链接呈现为 gt 表中的真正超链接。我的代码似乎不起作用。
非常感谢任何建议。

library(tidyverse)
library(gt)

mtcars %>% 
          rownames_to_column("make") %>%
          head() %>%
          mutate(make = paste0("<a href = 'www.google.com'>",make, "</a>")) %>%
          mutate(make = ifelse(is.na(make), "", make), 
                 make = map(make, gt::html)) %>%
          gt(groupname_col= "make", 
             rownames_to_stub = TRUE) 

【问题讨论】:

    标签: r gt


    【解决方案1】:

    这是否更接近您正在寻找的东西?

    mtcars %>% 
      rownames_to_column("make") %>%
      head() %>%
      mutate(link = paste0("https://www.google.com/search?q=", make)) %>% 
      mutate(
        link = map(link, ~ htmltools::a(href = .x, "Link to Google Search")),
        link = map(link, ~ gt::html(as.character(.x)))) %>% 
      gt(groupname_col= "make", 
         rownames_to_stub = TRUE) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多