首页 > 解决方案 > Actionbutton在R闪亮中第一次不起作用

问题描述

我已将此代码用于一个简单的应用程序,以从用户那里接收系统和站点名称。我第二次按“提交”按钮时遇到问题。例如,如果用户在没有选择系统/选择站点的情况下直接按“提交”,则会弹出“请确保系统不为空”。这是第一次按“提交”,但是当用户选择了系统并且站点然后第二次按“提交”时,它不起作用。有谁知道如何解决它?

这是我的代码。

library(shiny)
library(shinyWidgets)
library(shinycssloaders)
library(shinythemes)
library(shinyTime)
library('tools')

# Define UI for application that draws a histogram
ui <- fluidPage(
  theme = shinytheme("cyborg"),
  
  # Application title
  titlePanel("test"),
  
  sidebarLayout(
    sidebarPanel(
      selectizeInput('system', '* Select System:', width = '100%',
                     choices = c("a","b","c"), multiple = FALSE,
                     options = list(
                       placeholder = 'Please Select Site',
                       onInitialize = I('function() { this.setValue(""); }')
                     )),
      

      selectizeInput('site', '* Select Site:', width = '100%',
                     choices = c("A","B","C"), multiple = FALSE,
                     options = list(
                       placeholder = 'Please Select Site',
                       onInitialize = I('function() { this.setValue(""); }')
                     )),
      hr(),
      actionBttn(inputId = "submit", label= "Submit for Processing")
    ),
    mainPanel(
      h4("Test review")
    )
  )
)
server <- function(input, output, session) {

  # observe submit
  observeEvent(input$submit, {
    print("test input submit button 2")
    if (input$system=="") {
      showModal(modalDialog(
        title = "Error",
        "Please  make sure system is not empty."
      ))
    }else if (input$site==""){
      print("test1")
      showModal(modalDialog(
        title = "Error",
        "Please make sure site is not empty."
      ))
    }else {
      showModal(modalDialog(
        title = "Good",
        "success"
      ))
      }
    }, once = TRUE)
}

# Run the application 
shinyApp(ui = ui, server = server)

标签: rshinyshinyapps

解决方案


推荐阅读