1

クリックされたactionButtonのラベルを取得する最良の方法は何ですか? ラベルが更新されたactionButtonがあります。ユーザーがクリックしたら、それをキャプチャする必要があります。input$action2.label と input$action2.text を試しましたが、どちらもうまくいきませんでした。

ui.R

library(shiny)

shinyUI( fluidPage(

tags$head(tags$style(
  HTML('
       { background-color: #dec4de;}
       #action4 { width: 275 px; color:red; background-color:yellow }
       #action1, #action2, #action3 { color:black; background-color:lime }
       body, label, input, button, select { font-family: "Arial"; }'
  )
)),    

titlePanel("My Shiny App!"),

sidebarLayout(
  sidebarPanel(
    tabsetPanel(type = "tabs", 
                tabPanel("About", "Developer Info here"), 
                tabPanel("How to Use", "User Docs"))

  ),

  mainPanel(
    img(src="capstone1.jpg", align = "center"),
    br(),br(),
    tags$textarea(id="stext", rows=3, cols=80, "Default value"),
    br(),br(),br(),
    actionButton("action1", "Action 1"),
    actionButton("action2", "Action 2"),
    actionButton("action3", "Action 3"),
    br(), br(),
    actionButton("action4", 
                   label = "High < < < <  PROBABILITY  > > > > Low")
  )
)))

サーバー.R

library(shiny)

shinyServer( function(input, output, session) {

   observeEvent(input$action1, {
      x <- input$stext
      print(input$action2.text)
      updateTextInput(session, "stext", value=paste(x, "Btn 1"))
   })

   observeEvent(input$action2, {
      x <- input$stext
      print(input$action2.label)
      updateTextInput(session, "stext", value=paste(x, "Btn 2"))
   })  

   observeEvent(input$action3, {
      x <- input$stext
      print(x)
      updateTextInput(session, "stext", value=paste(x, "Btn 3"))
   })  

})

更新:shinyBSのコードを追加する

ui.R

{
   library(shinyBS)
   ....
   bsButton("myBtn", "")
   ...

}

サーバー.R

{
     ....
     updateButton(session, "myBtn", "New Label")
     ....
}
4

1 に答える 1