Masoud
Masoud

Reputation: 595

Paste function not working in title of shiny app in R

I am trying to add some text to the current title in shiny app. So I used

paste("Hello Shiny!", textOutput("text1"))

in the title but unfortunately something is wrong. The output and R code are as follows:

enter image description here

library(shiny)

ui <- fluidPage(
  titlePanel(
    title=
    #textOutput("text1")#
    paste("Hello Shiny!", textOutput("text1")))
)

server <- function(input, output) {
  output$text1<-renderText({"Title changed dynamically"})
}
shinyApp(ui = ui, server = server)

What's wrong with the code?

Upvotes: 1

Views: 299

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

Paste the data on the server side -

library(shiny)

ui <- fluidPage(
  titlePanel(
    title= textOutput("text1"))
)

server <- function(input, output) {
  output$text1<-renderText({
    dynamic_title <- "Title changed dynamically"
    paste("Hello Shiny!", dynamic_title)})
}
shinyApp(ui = ui, server = server)

enter image description here

Upvotes: 3

Related Questions