I know that I can set a fixed width or height using the width parameter in the plotOutput() function. However, in my Shiny application, the length of the image changes based on user input, so I don’t want to use a fixed width.
I’ve searched for related questions but couldn’t find a solution to my problem. Below is a reproducible example. As you can see, due to the image being too long, part of the image is not displayed in the Shiny interface. Is there any way to add a scrollbar so that users can scroll to view the remaining part of the image?
Thank you in advance for any suggestions!
library(shiny)
library(forestploter)
library(bslib)
# Define UI
ui <- fluidPage(
titlePanel("Forest Plot"),
sidebarLayout(
sidebarPanel(
h4("Forest Plot Example")
),
mainPanel(
plotOutput("forestPlot")
)
)
)
# Define server logic
server <- function(input, output) {
output$forestPlot <- renderPlot({
# Load example data
dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))
dt <- dt[1:6,1:6]
dt$` ` <- paste(rep(" ", 20), collapse = " ")
dt$Subgroup1 <- dt$Subgroup
dt$Subgroup2 <- dt$Subgroup
dt$Subgroup3 <- dt$Subgroup
dt$Subgroup4 <- dt$Subgroup
dt$Subgroup5 <- dt$Subgroup
dt$Subgroup6 <- dt$Subgroup
dt$Subgroup7 <- dt$Subgroup
dt$Subgroup8 <- dt$Subgroup
dt$Subgroup9 <- dt$Subgroup
dt$Subgroup10 <- dt$Subgroup
dt$Subgroup11 <- dt$Subgroup
dt$Subgroup12 <- dt$Subgroup
dt$Subgroup13 <- dt$Subgroup
dt$Subgroup14 <- dt$Subgroup
dt$Subgroup15 <- dt$Subgroup
dt$Subgroup16 <- dt$Subgroup
# names(dt)
# a long long plot
forest(dt[,c(1:3,8:23, 7)],
est = dt$est,
lower = dt$low,
upper = dt$hi,
ci_column = 20)
})
}
# Run the application
shinyApp(ui = ui, server = server)