There is certainly a better way that would involve using javascript to determine the text output size, and basing the plot on that.
Or of stipulating the text size dynamically based on the text and analysis thereof, and then using that on the plot also.
But aside from that here is a rough approach based on some assumption that there is some linear relationship between your typical text content and its plotted height.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(ggplot2)
library(shinipsum)
# Define UI for application that draws a histogram
ui <- shinydashboardPlus::dashboardPagePlus(
# Application title
header = shinydashboardPlus::dashboardHeaderPlus(title = "Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebar = shinydashboard::dashboardSidebar(),
body = shinydashboard::dashboardBody(
fluidRow(sliderInput("nwords",label="How many words?",min=1,max=300,value=40)),
fluidRow(sliderInput("scale_factor",label="scale factor ?",min=.1,max=4,value=2,step=.1)),
fluidRow(
shinydashboard::box(
title = "Text + plot box",
column(width = 6,
textOutput(outputId = "text")),
column(width = 6,
plotOutput(outputId = "ran_plot"))
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
randtext <- reactive({
shinipsum::random_text(nwords = req(input$nwords))
})
output$text <- renderText({
req(randtext())
})
output$ran_plot <- renderPlot({
shinipsum::random_ggplot()
}, height=function(){req(input$scale_factor)*req(input$nwords)})
}
# Run the application
shinyApp(ui = ui, server = server)