How to update button labels in R Shiny?

后端 未结 4 1887
独厮守ぢ
独厮守ぢ 2021-01-20 00:10

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 butto

4条回答
  •  时光说笑
    2021-01-20 00:48

    Also may be useful bsButton from shinyBS. It allows change button style almost completely. Tray next shiny app for example

    library(shiny)
    library(shinyBS)
    
    ui <- function() {
        fixedPage(
            br(),
            # Button settings----
            fluidRow(
    
                column(
                    3,
                    align = "center",
                    textInput(
                        "label", 
                        "Button label"
                    ),
                    actionButton(
                        "set_label",
                        "Set label"
                    )
                ),
    
                column(
                    3,
                    align = "center",
                    selectInput(
                        "style", 
                        "Button style", 
                        choices = c(
                            "default",
                            "primary", 
                            "success", 
                            "info", 
                            "warning", 
                            "danger"
                        )
                    ),
                    actionButton(
                        "set_style", 
                        "Set style"
                    )
                ),
    
                column(
                    3,
                    align = "center",
                    selectInput(
                        "size", 
                        "Button size", 
                        choices = c(
                            "extra-small",
                            "small", 
                            "default", 
                            "large"
                        )
                    ),
                    actionButton(
                        "set_size", 
                        "Set size"
                    )
                ),
    
                column(
                    3,
                    align = "center",
                    selectInput(
                        "icon", 
                        "Button icon",
                        selected = NULL,
                        choices = c(
                            "",
                            "android",
                            "apple"
                        )
                    ),
                    actionButton(
                        "set_icon", 
                        "Set icon"
                    )
                )
            ),
    
            br(),
            # Сhangeable button ----
            fluidRow(
                column(
                    12,
                    align = "center",
                    h3("Сhangeable button"),
                    shinyBS::bsButton(
                        "action",
                        label = "initial",
                        icon = icon(NULL)
                    )
                )
            )
        )
    }
    
    server = function(input, output, session){
    
        observeEvent(input$set_label, {
            shinyBS::updateButton(session, "action", label = input$label)
        })
    
        observeEvent(input$set_style, {
            shinyBS::updateButton(session, "action", style = input$style)
        })
    
        observeEvent(input$set_size, {
            shinyBS::updateButton(session, "action", size = input$size)
        })
    
        observeEvent(input$set_icon, {
            shinyBS::updateButton(session, "action", icon = icon(input$icon))
        })
    }
    
    runApp(list(ui = ui, server = server))
    

    Here you could make "danger large android" it's look pretty well :)

提交回复
热议问题