ggplot title as reactive text input?

My text input displays exactly whatever is typed inside it. But how do I make that same input as the title of my plot? (In this case the plot title should be test123)

Minimal reproducible example:

library(shiny)
library(ggplot2)

ui <- fluidPage(
  titlePanel("test"),
  
  sidebarLayout(
    sidebarPanel(
      
      textInput("caption", "Caption", "test123"),
      verbatimTextOutput("my_text")
      
      
      
    ),
    
    mainPanel(
plotOutput("my_plot")
    )
  )
)

server <- function(input, output) {
  
  output$my_text <- renderText({ input$caption })
  
  output$my_plot <- renderPlot(
    ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point() + ggtitle("default_label")
  )
  
}

shinyApp(ui, server)

+ ggtitle(req(input$caption))
1 Like

Thanks!

I haven't used req before - going to read up on it. Appreciated!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.