Reputation: 99
I am trying to display text in Shiny. 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:
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'))))
}
})
}
shinyApp(ui = ui, server = server)
Is there a way to render the HTML code into an actual button?
Upvotes: 0
Views: 771
Reputation: 727
How about the following?
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({
HTML(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',input$user_text))))
}
})
}
shinyApp(ui = ui, server = server)
Upvotes: 1