I'm currently training to build a shiny app.
I want to make a value box, the value is based on text input, and its updating after click action button
I use this script:
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")
)
})
}
)
And it show error:
Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
[No stack trace available]
I also try using numericInput
instead of textInput
and error still appear.
Can anyone tell me how to do it correctly?
You should access it as a function with update_unicode()
, also you got your button name wrong its 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")
)
})
}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.