Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

My plot don't fit into my navPanel #262

Open
Fatheeer opened this issue Aug 30, 2024 · 0 comments
Open

My plot don't fit into my navPanel #262

Fatheeer opened this issue Aug 30, 2024 · 0 comments

Comments

@Fatheeer
Copy link

I'm working on a shiny app with different navPanel(). When I select a navPanel I've reactive() that changes the plots. These plots are built based on a function(). Thus they are built in the same way. However when I select a specific navPanel() named "ZV" the plot appears bigger than his mates. To be more explicit please see the screens :

When I select "ZV" Panel:
[when I select "ZV" Panel] (https://i.sstatic.net/08jbX2CY.png)

When I select another Panel:
[when I select another Panel] (https://i.sstatic.net/fzcksqN6.png)

Here's the plot function code:

plot_FI <- function(data, x, y, z, title, title_y, title_x, coef, title_yy){
  ggplot(data = data) +
    aes_string(x = x, y = y) +
    geom_col(aes_string(fill = y)) +
    geom_line(aes_string(x = x, y = paste0(z, " * ", coef), group = 1), color = "white", linetype = "dotted", linewidth = 1, alpha = 0.6) +
    geom_text(aes_string(y = paste0(z, " * ", coef), label = z), nudge_y = -0.5, color = "white", size =4.5) + 
    scale_fill_gradient(low = "#CC0000", high = "lightgreen", limits = c(0, 20), guide = "none") + 
    scale_y_continuous(sec.axis = sec_axis(~. / coef - 2, name = title_yy)) +
    labs(title = title, x = title_x, y = title_y) +
    theme_minimal(base_size = 10) %+replace%    #
    theme(
      panel.background = element_rect(fill = "#444444"),
      panel.grid = element_blank(),
      legend.position = "bottom",
      axis.text.x = element_text(angle = 0,
                                 vjust = 1,
                                 hjust = 1, 
                                 size = 8,
                                 color = "white"),
      plot.background = element_rect(fill = "#444444"),
      axis.line = element_line(color = "white"),
      plot.title = element_text(size = 18),
      axis.text.y = element_text(size = 8,
                                 color = "white"),
      axis.title.x = element_text(size = 12),
      axis.title.y = element_text(size = 12, angle = 90),
      text = element_text(color = "white"))
  
}

The shiny code :

ui <- page_navbar(
  
  theme = bs_theme(bootswatch = "darkly",
                   success = "#FF6600",
                   base_font = font_google("Source Code Pro")),
  
  title = "Module Préparation Physique",
  
  sidebar = sidebar(
    dateRangeInput("periode", "Période :",
                   start = min(Data_binded$Date),
                   end = max(Data_binded$Date)),
    
    selectInput(
      "annotation", "Nom de séquence :",
      choices = Data_binded |> pull(Annotation_Name) |> factor() |> levels()
    ),
    
    selectInput(
      "annotation_name", "Séquence Indice de Fatigue :",
      choices = Data_4_Grouped |> pull(Final_Group) |> factor() |> levels()
    ),
    
    HTML('<img src = "logo narbonne.png" width = "100%" height = "auto">')
    
  ),
  navset_card_tab(
    title = tags$span("Séquences de jeu", class = "text-success"),
# [...]
    nav_panel("ZV", layout_columns(plotlyOutput("graph_zv_1", width = "100%", height = "400px"),
                                   plotlyOutput("graph_zv", width = "100%", height = "400px"),
                                   plotlyOutput("graph_zv_2", width = "100%", height = "400px"),
                                   plotlyOutput("graph_zv_3", width = "100%", height = "400px"),
                                   col_widths = c(8,4,8,4)))
# [...]

server <- function(input, output){

# [...]

  ZV_3 <- reactive({
    Zone_verte_4 |> 
      filter(Date >= input$periode[1] & Date <= input$periode[2]) |>
      filter(Final_Group == input$annotation_name)
  })

# [...]

  output$graph_zv_3 <- renderPlotly({
    data_graph_zv_3 <- ZV_3()
    coeff_zv <- max(data_graph_zv_3$Note_Equipe, na.rm = TRUE) / max(data_graph_zv_3$Indice_Fatigue, na.rm = TRUE)
    p_ZV <- plot_FI(data_graph_zv_3, "Annotation_Name", "Note_Equipe", "Indice_Fatigue", "Indicateur de fatigue", "Notes collectives", "Séquences successives", coeff_zv, "Indice de fatigue(%) (pointillé)")
    ggplotly(p_ZV)
  })

A reproducible example :

dput(Zone_verte_4)
structure(list(Annotation = c("ZV", "ZV", "ZV", "ZV", "ZV", "ZV", 
"ZV", "ZV", "ZV"), Annotation_Name = c("Relance Bleu 1", "Relance Bleu 2", 
"Relance Bleu 3", "Relance Rouge 1", "Relance Rouge 2", "ZV Bleu 1", 
"ZV Bleu 2", "ZV Rouge 1", "ZV Rouge 2"), Nom = c("Betham", "Betham", 
"Betham", "Betham", "Betham", "Betham", "Betham", "Chauvet", 
"Chauvet"), Date = structure(c(19947, 19947, 19947, 19947, 19947, 
19944, 19944, 19944, 19944), class = "Date"), Note_Equipe = c(12.9, 
8.5, 13.3, 2.3, 6, 2, 3.4, 10.3, 13), Final_Group = c("Relance Bleu ", 
"Relance Bleu ", "Relance Bleu ", "Relance Rouge ", "Relance Rouge ", 
"ZV Bleu ", "ZV Bleu ", "ZV Rouge ", "ZV Rouge "), Group_chiffre = c(1L, 
2L, 3L, 1L, 2L, 1L, 2L, 1L, 2L), Note_Max = c(12.9, 12.9, 12.9, 
2.3, 2.3, 2, 2, 10.3, 10.3), Indice_Fatigue = c(0, -34, 3, 0, 
161, 0, 70, 0, 26)), class = c("grouped_df", "tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -9L), groups = structure(list(
    Final_Group = c("Relance Bleu ", "Relance Rouge ", "ZV Bleu ", 
    "ZV Rouge "), .rows = structure(list(1:3, 4:5, 6:7, 8:9), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -4L), .drop = TRUE))

I tried to fix the width and the height as you can see in the navPanel() and it worked only when I loaded the app locally. But when I tried to load the app into shinyapps.io the issue was still present. I think it's more like a bug issue than anything but do you have any solutions please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant