Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding multiple resource links #13

Open
ddsjoberg opened this issue Nov 14, 2023 · 0 comments
Open

Adding multiple resource links #13

ddsjoberg opened this issue Nov 14, 2023 · 0 comments

Comments

@ddsjoberg
Copy link
Collaborator

For now, there is only one link per variable. But if in the future, there is more than one, this code could be helpful:

library(reactable)

df <- data.frame(
  ID = "Link to the right of this text",
  url1_text = "Pharmaverse Repo",
  url1 = "https://github.com/pharmaverse/falcon",
  url2_text = "ddsjoberg forked Repo",
  url2 = "https://github.com/ddsjoberg/falcon"
)

rtbl <-
  df |>
  dplyr::select(ID, url1) |>
  reactable(
    columns = list(
      url1 = colDef(
        name = "URL",
        cell = function(value, index) {
          label1 <- df[index, "url1_text"]
          label2 <- df[index, "url2_text"]
          url1 <- df[index, "url1"]
          url2 <- df[index, "url2"]
          htmltools::div(
            htmltools::p(
              htmltools::tags$a(href = url1, target = "_blank", label1)
            ),
            htmltools::p(
              htmltools::tags$a(href = url2, target = "_blank", label2)
            )
          )
        }
      )
    )
  )

df <- data.frame(
  link_text = "Template",
  url1 = "https://www.cnn.com/",
  url2 = "https://www.bbc.com/news",
  two_links = NA)


reactable(df, columns = list(
  two_links = colDef(html = TRUE, cell = JS('
    function(cellInfo) {
      const url1 = ${cellInfo.row["url1"]}
      const url2 = ${cellInfo.row["url2"]}
      return `<a href="${url1}">cnn</a> <br>
        <a href="${url2}">bcc</a>`
    }
  '))
))

library(tidyverse)

tibble(
  link_text = "Template",
  link_url = "https://github.com/ddsjoberg/falcon"
) |> 
  mutate(
    markdown = glue::glue("[{link_text}]({link_url})"),
    two_links = glue::glue("{markdown}\n\n{markdown}")
  ) |> 
  gt::gt() |> 
  gt::fmt_markdown()
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

1 participant