Search code examples
rshinyradar-chart

How to create a radar chart in Shiny?


I have an assignment due tonight and I have to create one last plot: a radar chart in Shiny.

I can't figure it out despite creating a "normal" radar chart using this code:

mvr <- fifa %>%

filter (year == 2021) %>%
  filter (short_name %in% c("L. Messi", "Cristiano Ronaldo")) %>%
  select (-"short_name", -"age", -"height_cm", -"weight_kg", -"nationality", -"club_name", -"league_rank", -"overall", -"potential", -"value_eur", -"wage_eur", -"preferred_foot", -"team_position", -"year", -"Position")

maxmin <- data.frame( Attack = c(99,0), Skill = c(99,0), Movement = c(99,0), Power = c(99,0), Mentality = c(99,0), Defense = c(99,0), Goalkeeping = c(99,0) )

rownames(maxmin) <- c("Max", "Min")

comparison <- bind_rows(maxmin, mvr)

radarchart(comparison)

My database is "fifa" composed of multiple rows of players and columns of player performance attributes, year, club name, etc. I want to only select two players each time and compare their performance attributes using a radar chart.

I want to recreate the code above for my Shiny dashboard. Any one has an idea ?

I wrote this:

  output$radar <- renderPlotly({
mvr <- filter(fifa, name == input$short_name) %>%
  select (-"short_name", -"age", -"height_cm", -"weight_kg", -"nationality", -"club_name", -"league_rank", -"overall", -"potential", -"value_eur", -"wage_eur", -"preferred_foot", -"team_position", -"year", -"Position")

maxmin <- data.frame( Attack = c(99,0), Skill = c(99,0), Movement = c(99,0), Power = c(99,0), Mentality = c(99,0), Defense = c(99,0), Goalkeeping = c(99,0) )
rownames(maxmin) <- c("Max", "Min")
comparison <- bind_rows(maxmin, mvr)

fig <- plot_ly(comparison)})

But it's not working.


Solution

  • Try this app on the Rstudio Shiny Gallery

    https://shiny.rstudio.com/gallery/soccer-player-similarity.html