Add a button next to statement in shiny

I am trying to display text in Shiny(server.R). But I also need to add a button next to the displayed text.

When when I open the application I can see the plain HTML content (but no button)

Shiny code sample below

library(shiny)

ui <- fluidPage(
  headerPanel("Example reactiveValues"),
  
  mainPanel(
    
    # input field
    textInput("user_text", label = "Enter some text:", placeholder = "Please enter some text."),
    actionButton("submit", label = "Submit"),
    
    # display text output
    textOutput("text"))
)

server <- function(input, output) {
  
  flag_1 <- TRUE
  
text_reactive = reactiveValues(text = "No values are updated")

output$text <- renderText({
  text_reactive$text
})

observeEvent(input$submit,{
  if(flag_1 <- FALSE)
  {
  text_reactive$text <- input$user_text
  }
  else {
    text_reactive$text <-  paste0("hi", HTML(as.character(actionButton('id','label'))))
  }
})

So, when you write something and click on submit, there should be "Hi" and a button

Is there a way to render the HTML code into an actual button?

library(shiny)

ui <- fluidPage(
  headerPanel("Example reactiveValues"),
  
  mainPanel(
    
    # input field
    textInput("user_text", label = "Enter some text:", placeholder = "Please enter some text."),
    actionButton("submit", label = "Submit"),
    
    # display text output
    uiOutput("text"))
)

server <- function(input, output) {
  
  flag_1 <- TRUE
  
  text_reactive = reactiveValues(text = "No values are updated")
  
  output$text <- renderUI({
    text_reactive$text
  })
  
  observeEvent(input$submit,{
    if(flag_1 <- FALSE)
    {
      text_reactive$text <- input$user_text
    }
    else {
      text_reactive$text <-  HTML(paste0("hi   ", as.character(actionButton('id','label'))))
    }
  })
}

shinyApp(ui, server)

This topic was automatically closed 54 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.