[英]Update valuebox using action button in R Shiny
我目前正在訓練構建 shiny 應用程序。
我想做一個值框,值基於文本輸入,點擊動作按鈕后更新
我使用這個腳本:
shinyApp(
ui <- dashboardPage(
dashboardHeader(
title = "Test action button"
),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(
textInput(
"unicode",
"Your Unique ID:",
placeholder = "Input your unique ID here"
),
actionButton(
"actbtn_unicode",
"Submit"
),
width = 8
),
valueBoxOutput(
"vbox_unicode"
)
),
)
),
server <- function(input, output){
update_unicode <- eventReactive(input$act_unicode,{
input$unicode
})
output$vbox_unicode <- renderValueBox({
valueBox(
update_unicode,
"Your Unique ID",
icon = icon("fingerprint")
)
})
}
)
它顯示錯誤:
Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
[No stack trace available]
我也嘗試使用numericInput
而不是textInput
並且仍然出現錯誤。
誰能告訴我如何正確地做到這一點?
您應該使用update_unicode()
作為 function 訪問它,而且您的按鈕名稱錯誤,它的input$actbtn_unicode
library(shiny)
library(shinydashboard)
shinyApp(
ui <- dashboardPage(
dashboardHeader(
title = "Test action button"
),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(
textInput(
"unicode",
"Your Unique ID:",
placeholder = "Input your unique ID here"
),
actionButton(
"actbtn_unicode",
"Submit"
),
width = 8
),
valueBoxOutput(
"vbox_unicode"
)
),
)
),
server <- function(input, output){
update_unicode <- eventReactive(input$actbtn_unicode,{
input$unicode
})
output$vbox_unicode <- renderValueBox({
valueBox(
update_unicode(),
"Your Unique ID",
icon = icon("fingerprint")
)
})
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.