I have a fluid dashboard with lots of graphs created in ggplot and then rendered as ggplotly objects. The problem is that on smaller screens or minimised windows, sometimes the plot titles are cut off.
Is there a way to dynamically wrap plot titles based on screen width, potentially with str_wrap()?
I've included a reproducible example below:
library(shiny)
library(tidyverse)
library(plotly)
ui <- fluidPage(
fluidRow(
column(
width = 4,
plotlyOutput("plot1")
),
column(
width = 4,
plotlyOutput("plot2")
),
column(
width = 4,
plotlyOutput("plot3")
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlotly({
x <- mtcars %>%
ggplot(
aes(
x = cyl,
y = hp,
fill = wt
)
) +
geom_point() +
labs(title = "My very, very, very long title number 1")
ggplotly(x)
})
output$plot3 <- renderPlotly({
x <- mtcars %>%
ggplot(
aes(
x = cyl,
y = hp,
fill = wt
)
) +
geom_point() +
labs(title = "My very, very, very long title number 2")
ggplotly(x)
})
output$plot2 <- renderPlotly({
x <- mtcars %>%
ggplot(
aes(
x = cyl,
y = hp,
fill = wt
)
) +
geom_point() +
labs(title = "My very, very, very long title number 3")
ggplotly(x)
})
}
# Run the application
shinyApp(ui = ui, server = server)