Render Images in Shiny

Can I pass a variable name inside a img src in Shiny?
I have a dataset in which in one column contains all images (Eg. df$player_image_url).
Can I pass tags$img(src=df$player_image_url) based on certain "if" conditions?

Hi, yes it's possible.
You can either write the if-else before the tags$img, or use ifelse(..) inside the tags$img.
Can you provide more details about this and the challenging part?

So I am building a Shiny app that has 3 Select Inputs League, Team, Player

If I select a tournament, team and the player the respective player image must be displayed

Player Image URL is in one particular column as mentioned(df$player_image_url)

How do I map this??



if(TournamentShortName %in% input$sel_tour1 &
    TeamName %in% input$sel_team1 ){


The above is the sample code that throws an error?

Okay. But I didn't understand the role of the variables TournamentShortName and TeamName.
The error can be also from the missing quote in the SAMPLE_img src.

So I assume that your df has already columns for the corresponding League, Team and Player. And there is only one row for each combination. The code to get the corresponding image url can be:

myimg = sources_metadata %>% filter(League==input$sel_tour1 & Team==input$sel_team1  & Player==input$selected_player) %>% pull(source_id)
## we test if we have the corresponding image in the df or not:
if(identical(myimg, character(0))){
tags$img(src= myimg ,height=30,width=30)

Getting the below error:
Input ..1 must be of size 71535 or 1, not size 0.
As you mentioned above my data has a respective League, Tournament, and player name and image URL in the data
but the sample image is loading but not the actual player images

I think some of the inputs are empty, you can add a req()( like req(input$sel_tour1 ) before that part of the code. It would be great if you can you provide a small shiny app with some data.


How do I get the player image from the URL from the column player_image_url?

If I select the TournamentShortName and TeamName and a respective player the player image must be displayed?

Hi, I am not sure what the exact problem is, can you clarify what you have been doing and what are the challenges you are having?
It looks like the data has repeated values for the same player, right? you can select unique player_image_url.

Yes, the data has repeated values for the same player,
I am building an player comparison App for Kabaddi

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.