Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update button labels in R Shiny?

The R Shiny website has a great example of how to update the labels and values of a variety of input types based on user input. However, I couldn't find anything for buttons. Specifically, how do I update the label for a button based on user input?

like image 875
bskaggs Avatar asked Dec 12 '22 02:12

bskaggs


1 Answers

You can dynamically create the Button like so, updating the labels at the same time:

library(shiny)

ui =(pageWithSidebar(
  headerPanel("Test Shiny App"),
  sidebarPanel(
    textInput("sample_text", "test", value = "0"),
    #display dynamic UI
    uiOutput("my_button")),
  mainPanel()
))

server = function(input, output, session){
  #make dynamic button
  output$my_button <- renderUI({
    actionButton("action", label = input$sample_text)
  })
}
runApp(list(ui = ui, server = server))
like image 52
Pork Chop Avatar answered Dec 13 '22 16:12

Pork Chop