获取单击的actionButton标签的最佳方法是什么?我有一个更新了标签的actionButton。当用户点击时,我需要捕捉它。我尝试了 input$action2.label 和 input$action2.text,但都没有成功。
用户界面
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 添加代码
用户界面
{
library(shinyBS)
....
bsButton("myBtn", "")
...
}
服务器.R
{
....
updateButton(session, "myBtn", "New Label")
....
}