R Shiny網站有一個great example關於如何根據用戶輸入更新各種輸入類型的標籤和值。但是,我找不到任何按鈕。具體來說,如何根據用戶輸入更新按鈕的標籤?如何更新R Shiny中的按鈕標籤?
3
A
回答
5
您可以動態創建像這樣的按鈕,同時更新標籤:
library(shiny)
ui =(pageWithSidebar(
headerPanel("Test Shiny App"),
sidebarPanel(
textInput("sample_text", "test", value = "0"),
#display dynamic UI
uiOutput("my_button")),
mainPanel()
))
server = function(input, output, session){
#make dynamic button
output$my_button <- renderUI({
actionButton("action", label = input$sample_text)
})
}
runApp(list(ui = ui, server = server))
2
如果你的按鈕已經建成,解決方案是使用圖書館「shinyjs」。
library(shinyjs)
# in UI section
shinyjs::useShinyjs()
# in Server section: call this function at any time to update the button label
runjs(paste0("$('label[for=\"YourButtonId\"]').text('",TextVariable,"')"))
0
updateActionButton
:
ui <- fluidPage(
actionButton('someButton', ""),
textInput("newLabel", "new Button Label:", value = "some label")
)
server <- function(input, output, session) {
observeEvent(input$newLabel, {
updateActionButton(session, "someButton", label = input$newLabel)
})
}
shinyApp(ui, server)
相關問題
- 1. 更新按鈕標籤
- 2. R Shiny單選按鈕不更新使用updateRadioButtons
- 3. 沒有按鈕的更新標籤
- 4. 如何在按下按鈕後動態更新Kivy標籤
- 5. 更改R Shiny fileInput中標籤文本的大小/間距?
- 6. 強制按鈕來更新其標籤
- 7. 如何更改alertify按鈕標籤 - v0.3.11
- 8. 如何更改點擊按鈕標籤?
- 9. 如何在Shiny中同時調用JavaScript和R代碼按鈕?
- 10. 禁用Shiny中的按鈕
- 11. 更改按鈕標籤
- 12. Kivy:單擊按鈕時如何更新標籤
- 13. wxpython中EVT_BUTTON的按鈕標籤更改?
- 14. 在ActionPane中更改按鈕的標籤
- 15. 如何使用Shiny中的操作按鈕更新默認的csv數據?
- 16. 如何更改DT/Shiny中ColumnVisibility按鈕的顏色
- 17. 如何通過在PySide中按下按鈕來更改標籤
- 18. 如何更改Rails 3中formtastic中按鈕的標籤?
- 19. R Shiny:如何創建一個「添加字段」按鈕
- 20. 更新網格中各個行的標籤的按鈕
- 21. R Shiny,如何在observeEvent調用中更新變量
- 22. Tkinter:通過按下按鈕更新標籤的值
- 23. jQuery:按類更新特定單選按鈕時的span標籤?
- 24. Tkinter - 更新標籤和調用方法的按鈕按
- 25. 更新按鈕回調中的標籤很困難
- 26. 按鈕標籤
- 27. 如何更改Symfony2.8/Twig中單選按鈕的標籤類別?
- 28. 如何用Xcode中的按鈕更改標籤文本?
- 29. 如何更改離子2中後退按鈕的標籤?
- 30. 如何更改NVD3中控制按鈕上的標籤?
'updateActionButton'? – 2017-08-29 07:54:24