0

I am working with this example hockey dataset (pbp_game_id):

structure(list(home_team = c("WPG", "PIT", "EDM", "S.J", "BOS", 
"BUF", "NYR", "OTT", "DET", "CHI"), away_team = c("TOR", "STL", 
"CGY", "PHI", "NSH", "MTL", "COL", "WSH", "MIN", "PIT")), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -10L))

Let's say I want to insert hockey team logos right next to those characters, like in this example: enter image description here

I have a vector of urls that contain team 31 logos:

c("http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Ducks_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Coyotes_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Bruins_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Sabres_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/carolina.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_BlueJackets_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/calgary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/chicago.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/colorado.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Stars_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/detroit.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Oilers_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Panthers_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Kings_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Wild_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/montreal.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/newjersey.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Predators_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NY-Islanders-Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/newyorkr.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Senators_Primary.png", 
"http://www.stickpng.com/assets/images/5a4fbba3da2b4f099b95da1a.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Penguins_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Sharks_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/stlouis.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Lightning_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_MapleLeafs_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/Vancouver_Canucks.png", 
"https://upload.wikimedia.org/wikipedia/en/thumb/a/ac/Vegas_Golden_Knights_logo.svg/184px-Vegas_Golden_Knights_logo.svg.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Jets_Primary.png", 
"http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Capitals_Primary.png"
)

I've tried this to insert the url image next to the text:

pbp_game_id %>%
   mutate(home_team = case_when(
    home_team == "ANA" ~ paste(team_logo[1], home_team),
    ...)

Skeleton UI

fluidRow(...
         column(4,
           DT::dataTableOutput("game_id_table"))

Server

 # Game ID Table
  output$game_id_table <- DT::renderDataTable({

    DT::datatable(pbp_game_id, extensions = "Scroller",
                  filter = "top", options = list(
                    deferRender = TRUE,
                    scrollY = 200,
                    scroller = TRUE
                  ),
                  rownames = FALSE,
                  colnames = c("Game ID",
                               "Game Date",
                               "Home",
                               "Away")
    )

I don't see no images rendering on my datatable. I just see plain url... What am I missing?

  • 1
    It would be very helpful if you provided the rest of a skeleton shiny app, perhaps just the table in the ui. – r2evans Feb 05 '19 at 20:39
  • @r2evans Just added. Thanks for the rec –  Feb 05 '19 at 20:42
  • 1
    https://stackoverflow.com/questions/30671958/how-to-embed-an-image-in-a-cell-a-table-using-dt-r-and-shiny. Did you check this post? The text you can just add to the html code,... – Tonio Liebrand Feb 05 '19 at 20:44
  • Yep I saw that post. I dont know how to add the text to the html code –  Feb 05 '19 at 20:46
  • 1
    `team_logo <- paste("")`? – r2evans Feb 05 '19 at 20:52
  • Wait @r2evans , this only adds team logo. Do you know how I can add `home_team` and `away_team` next to team logo? just like in the example I provided in my OP –  Feb 06 '19 at 18:45

0 Answers0