[英]How can I use observeEvent capture the HTML input id in shiny?
如何使用 observeEvent 捕獲 shiny 中的 HTML 輸入 id?
shinyApp(
ui = basicPage( HTML('<input type="button" name = "b1" value="Travel time"/>')),
server = function(input, output, session) {
observeEvent(input$b1, {
print(paste("This will only be printed once; all",
"subsequent button clicks won't do anything"))
}, once = TRUE)
}
)
我想實現 function 在 shiny 中使用 HTML,當我點擊“旅行時間”時,可以觀察到事件。
無需添加 package:
shinyApp(
ui = basicPage(
HTML('<button type="button" id="b1" class="action-button">Travel time</button>')
),
server = function(input, output, session) {
observeEvent(input$b1, {
print(paste("This will only be printed once; all",
"subsequent button clicks won't do anything"))
}, once = TRUE)
}
)
你可以用shinyjs
package 解決這個問題
shinyApp(
ui = basicPage(
shinyjs::useShinyjs(),
HTML('<input type="button" id = "b1" value="Travel time"/>')
),
server = function(input, output, session) {
shinyjs::onclick(
"b1",
{
shinyjs::disable(id = "b1")
print(paste("This will only be printed once; all",
"subsequent button clicks won't do anything"))
}
)
}
)
希望這可以幫助!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.