I'm not aware of any package for doing this, but you can use something like this example, and fine tune the screen ratio/number of characters relationship for your specific application
library(shiny)
library(stringr)
library(ggplot2)
shinyApp(
ui = basicPage(
tags$head(tags$script('
var dimension = [0, 0];
$(document).on("shiny:connected", function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
$(window).resize(function(e) {
dimension[0] = window.innerWidth;
dimension[1] = window.innerHeight;
Shiny.onInputChange("dimension", dimension);
});
')),
mainPanel(
textInput("title",
label = h5("Plot Title"),
value = "How many times did the board meet during 2017"),
plotOutput("plot")
)
),
server = function(input, output) {
output$plot <- renderPlot({
wraped_title <- str_wrap(input$title,
width = input$dimension[1]/10)
iris %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point() +
labs(title = wraped_title)
})
}
)