0
はvalidate()
機能の動作を示している。このexample app from the shiny docsを取る:表示検証エラーメッセージに一度だけ
## server.R
`%then%` <- shiny:::`%OR%`
shinyServer(function(input, output) {
data <- reactive({
validate(
need(input$data != "", "Please select a data set") %then%
need(input$data %in% c("mtcars", "faithful", "iris"),
"Unrecognized data set") %then%
need(input$data, "Input is an empty string") %then%
need(!is.null(input$data),
"Input is not an empty string, it is NULL")
)
get(input$data, 'package:datasets')
})
output$plot <- renderPlot({
hist(data()[, 1], col = 'forestgreen', border = 'white')
})
output$table <- renderTable({
head(data())
})
})
## ui.R
shinyUI(fluidPage(
tags$head(
tags$style(HTML("
.shiny-output-error-validation {
color: green;
}
"))
),
titlePanel("Validation App"),
sidebarLayout(
sidebarPanel(
selectInput("data", label = "Data set",
choices = c("", "mtcars", "faithful", "iris"))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot"),
tableOutput("table")
)
)
))
は同じので、アプリは一度の代わりに、二回validate
エラーメッセージを表示させる方法はありますplot
の場合はの検証が1回失敗し、table
の要素の場合は1回失敗しますか?