I have a shiny app with a title, one plot, some description and an actionButton. I want the elements to be aligned as follows:
- title on top;
- description and actionButton at the bottom;
- plot in between resizing according to the monitor resolution.
My app.R
looks as follows:
library(shiny)
text <- list(
"one",
"one\ntwo",
"one\ntwo\nthree",
"one\ntwo\nthree\nfour"
)
ui <- fluidPage(
titlePanel("title"),
fluidRow(plotOutput("plot")),
fluidRow(style = "position:absolute;bottom:20px;left:20px",
verbatimTextOutput("text"),
actionButton("next_el", ">>")
)
)
server <- function(input, output) {
output$plot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$next_el + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$text <- renderText(text[[input$next_el + 1]])
observeEvent(input$next_el, {})
}
# Run the application
shinyApp(ui = ui, server = server)
What I have at the moment: title, description and actionButton are placed ok on desktop and on mobile screens. description also resizes with the amount of text present.
However, the plot does not resize properly: On mobile devices the description is placed over the plot. On the other side on desktop devices the plot only uses about half the screen.
I tried resizing the plot with plotOutput("plot", height = "50%")
and plotOutput("plot", height = "auto")
, but then the plot disappears.
What can I do in order my plot resizes up if there's enough space and resizes down if there's not enough space?