Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 情态动词的顺序使用_R_Shiny - Fatal编程技术网

R 情态动词的顺序使用

R 情态动词的顺序使用,r,shiny,R,Shiny,我想检查一些用户输入的数据,测试一些条件,并通过modalDialog()发出警报,以获得更多的用户输入(例如,提示X为NA;这是否正确?Y/N) 但是,我发现,如果我在一个observeEvent中放入多个showmodel(modalDialogFunction())调用,则只会为用户计算最后一个调用,因为会弹出模式等。print语句验证是否满足条件 如何以这种或类似的格式执行顺序模态 单文件应用程序:使用numericInput()s查看模态是如何执行的 ui <- fluidPag

我想检查一些用户输入的数据,测试一些条件,并通过
modalDialog()
发出警报,以获得更多的用户输入(例如,提示
X为NA;这是否正确?Y/N

但是,我发现,如果我在一个
observeEvent
中放入多个
showmodel(modalDialogFunction())
调用,则只会为用户计算最后一个调用,因为会弹出模式等。
print
语句验证是否满足条件

如何以这种或类似的格式执行顺序模态

单文件应用程序:使用
numericInput()
s查看模态是如何执行的

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      numericInput("first", label="First", value=0),
      numericInput("second", label="Second", value=0)
    ),
    mainPanel(
      actionButton("click", label="Click")
    )
  )
)

server <- function(input, output) {
  firstModal <- function(){
    modalDialog(
      p("First is greater than zero"),
      actionButton("clickHere", label="Click to continue")
    )
  }

  secondModal <- function(){
    modalDialog(
      p("Second is greater than zero"),
      actionButton("clickAgain", label="Click to continue again")
    )
  }

  observeEvent(input$click, {
    if(input$first>0){
      print("First is greater than 0")
      showModal(firstModal())
    }

    if(input$second>0){
      print("Second is greater than 0")
      showModal(secondModal())
    }
  })
}

shinyApp(ui = ui, server = server)

ui我发现不可能让两个输入按钮具有相同的ID并且同时可见。为了解决这个问题,打开第一个模态的按钮需要一个不同的ID——模态中的所有“下一个”按钮可以共享一个ID,因为它们永远不会同时可见。检查此工作示例:

ui <- fluidPage(
      actionButton("openFirst", label="Click")
)

server <- function(input, output) {

  # function to create a modal, can be different functions as well
  makeModal <- function(text){
    modalDialog(
      footer=list(actionButton("click", label="Click to continue"), modalButton("Close")),
      numericInput("number", "Enter a number", value=0),
      p(text)
    )
  }

  # open the first modal
  observeEvent(input$openFirst, {
    showModal(makeModal("first one opened"))
  })

  # open a new modal at button click.
  observeEvent(input$click, {
    if(input$number > 15){ showModal(makeModal("input was greater than 15!"))
    }else if(input$number > 5){ showModal(makeModal("input was greater than five!"))
    }else{
      showModal(makeModal("Input was not greater than five!"))
    }
  })
}

shinyApp(ui = ui, server = server)

ui您是否尝试过使用两种不同的
observeEvent
s?我不希望这样做,因为在添加许多此类条件时,这将更难跟踪(即,基于上一个模式中的按钮进行下一次测试,这将需要在新模式中创建的新按钮上,将连续条件构建到新的
观察事件
)很好,我喜欢这个解决方案。您能扩展您的答案,以根据外部数据检查的条件显示模式吗(即不依赖于
modalCounter
)?我想显示/不显示模式(并从该模式收集输入)基于是否满足某些外部条件,如我问题中的
数值输入
s。我不知道如何调整您的答案。对于这种行为,不需要计数器。调整示例以在模态中对输入作出反应。@shosaco这不完全是我面临的问题。在我的示例中,当两个满足了
observeEvent(input$click,{…
中的条件。在这种情况下,只执行最后一个模式。在没有重叠ID的情况下也会发生这种情况。我认为这是正确的,因为这两个条件都满足了,并且您没有使用
if(){}else{}
。。。