【问题标题】:Actionbutton shown only when Selectinput changes [closed]仅当 Selectinput 更改时才显示操作按钮 [关闭]
【发布时间】:2020-11-28 19:31:09
【问题描述】:

只有当 Selectinput 改变时,有没有办法以闪亮的方式显示动作按钮?例如,假设我从 selectinput 中选择了选项 A。此时操作按钮将被禁用,但只要我在 A 之外添加选项 B(当您删除选项 B 时反之亦然),操作按钮将再次显示以确认这些更改?对于没有提供可重现的示例,我提前道歉,因为我不知道如何处理它。

【问题讨论】:

    标签: r shiny shinyjs


    【解决方案1】:

    也许你正在寻找这个

    ui <- fluidPage(
        sidebarLayout(
          sidebarPanel(
            selectInput("actionona", "actionbutton on demand", c("A", "B"), selected=1),
            selectInput("actiondisableb", "Disable When D is selected", c("C", "D")),
            fluidRow( uiOutput("action1"), uiOutput("action2"))
          ),
    
          mainPanel(
            uiOutput('myvalue1'),
            uiOutput('myvalue2')
          )
        )
    )
    
    server <- function(input, output, session){
      
      output$action1 <-  renderUI({
        if(input$actionona=="A"){
          actionBttn(inputId="plotbtn", 
                     label="Action One",
                     style = "simple",
                     color = "success",
                     size = "md",
                     block = FALSE,
                     no_outline = TRUE
          )
        }else{
          return(NULL)
        }
        
      })
      
      output$action2 <-  renderUI({
        req(input$actiondisableb)
        if (is.null(input$actiondisableb)) {
          return(NULL)
        }
        else {
          actionBttn(inputId="plotmebtn", 
                     label="Action Two",
                     style = "simple",
                     color = "primary",
                     size = "md",
                     block = FALSE,
                     no_outline = TRUE
          )
        }
      })
      
      observeEvent(input$plotbtn, {
        req(input$plotbtn)
        if (input$plotbtn==0) {
          return(NULL)
        }else {
          output$myvalue1 <- renderUI({
            if (input$actionona=="A") {
              tagList(
                p("Blah Blah Blah 1", style = "color:red")
              )
              
            }else {return(NULL)}
          })
        }
        
      })
      
      observeEvent(input$plotmebtn, {
        req(input$actiondisableb,input$plotmebtn)
        if (input$plotmebtn==0) {
          return(NULL)
        }else {
          output$myvalue2 <- renderUI({
            if (input$actiondisableb=="C") {
              tagList(
                p("Blah Blah Blah 2", style = "color:blue")
              )
            }else {return(NULL)}
          })
        }
        
      })
      
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 非常感谢 YBS。这非常有帮助:)
    猜你喜欢
    • 2017-04-11
    • 2012-05-01
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2017-05-13
    • 2017-09-28
    相关资源
    最近更新 更多