简体   繁体   中英

How can I concatenate non-reactive values with reactive value for a graph title? R Shiny

I am having trouble naming a graph title that contains a normal string AND reactive value/s.

I'm trying to do something like this: main = "Examination of: " + input$userInput

The error message is: non-numeric argument to binary operator. Does anyone know how to fix this?

The below code could give you what you needed.

library(shiny)
ui <- basicPage(
  uiOutput("test"),
  plotOutput("plot1")
)
server <- function(input, output) {
  output$test <- renderUI({
    selectInput("dummy", "Select one value", c(mtcars$qsec))
  })
  output$plot1 <- renderPlot({
    plot(mtcars$wt, mtcars$mpg, main = paste0("this is main ",input$dummy,""))
  })
}
shinyApp(ui, server)

The usage of selectInput is for testing your requirement. Make the needful changes for your actual problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM