OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Freezing the axis-labels on top of figure in R shiny

  • Thread starter Thread starter Majid
  • Start date Start date
M

Majid

Guest
I have a renderGirafe that is very long. I want the user to be able to see the x-axis values (which are on top of figure) after scrolling down.

Here is a sample code. In this code, I want the user to still be able to see the years when he/she scrolls down. I'm pretty flexible with what type of plot to be generated, as long as it shows the labels when hovering the mouse over each block. Suggestions are welcome!

Code:
library(shiny)
library(tidyverse)
library(ggiraph)

ui <- fluidRow(girafeOutput("my_plot"))

server <- function(input, output){
  output$my_plot <- renderGirafe({
    
    data <- data.frame(
      letter = rep(c(LETTERS, letters, paste0(LETTERS, letters))),
      year = factor(rep_len(2000:2008, 78)),
      value = floor(runif(78, 1, 6))
    )
    
    g <- ggplot(data) + 
      geom_tile_interactive(aes(x = year, y = letter, fill = value, tooltip = value)) + 
      scale_x_discrete(position = "top") + 
      coord_fixed() +
      theme_classic() + 
      theme(axis.text.x = element_text(
        angle = 90,
        hjust = 0.5,
        vjust = 0,
        size = 17
      )) 
    
    girafe(ggobj = g,  
           options = list(opts_sizing(rescale = F)),
           width_svg = 20,
           height_svg = 50
    )
  })
}

shinyApp(ui = ui, server = server)

<p>I have a renderGirafe that is very long. I want the user to be able to see the x-axis values (which are on top of figure) after scrolling down.</p>
<p>Here is a sample code. In this code, I want the user to still be able to see the years when he/she scrolls down. I'm pretty flexible with what type of plot to be generated, as long as it shows the labels when hovering the mouse over each block. Suggestions are welcome!</p>
<pre><code>library(shiny)
library(tidyverse)
library(ggiraph)

ui <- fluidRow(girafeOutput("my_plot"))

server <- function(input, output){
output$my_plot <- renderGirafe({

data <- data.frame(
letter = rep(c(LETTERS, letters, paste0(LETTERS, letters))),
year = factor(rep_len(2000:2008, 78)),
value = floor(runif(78, 1, 6))
)

g <- ggplot(data) +
geom_tile_interactive(aes(x = year, y = letter, fill = value, tooltip = value)) +
scale_x_discrete(position = "top") +
coord_fixed() +
theme_classic() +
theme(axis.text.x = element_text(
angle = 90,
hjust = 0.5,
vjust = 0,
size = 17
))

girafe(ggobj = g,
options = list(opts_sizing(rescale = F)),
width_svg = 20,
height_svg = 50
)
})
}

shinyApp(ui = ui, server = server)
</code></pre>
 
Top