如何为 R Shiny 中的单个 fileInput() 的 selectInputs() 的给定组合分配不同的进程?

How do I assign to a given combination of selectInputs() a different process for one single fileInput() in R Shiny?

我整天都在搜索,但我没有找到我的问题的解决方案,我认为这是根本性的。另外,我刚刚用 shiny 编码了两天,所以我在 Web 应用程序开发方面是个新手。

这是问题所在:

假设我有 selectInput1()selectInput2()fileInput()

library(shiny)

ui = fluidPage(
  titlePanel("Help me please"),
  sidebarLayout(
    sidebarPanel(

    selectInput("select1", "command 1",choices = c("V","W")),       # command 1
    selectInput("select2", "command 2",choices = c("a","b","c")),   # command 2

    fileInput("file", "raw", multiple = TRUE, accept = c("text/csv", ".csv") # Input
                )
               ),
    mainPanel(
            verbatimTextOutpu("Final1"),     #Here I display the result 1
            verbatimTextOutpu("Final2")      # here displays the result 2

            )
               )
              )

server = function(input,output){

}

shinyApp(ui, server)

现在,假设有 2*3 = 6 种方法(组合)来处理 fileInput。 让我们说:

P_{i,j}(x) := "Process i,j of x"

其中 x 是 selectInputs

fileInputi %in% c("V","W")i %in% c("a", "b" , "c") 选项

我需要一种在服务器 fileInput 中以与 if 语句类似的方式进行处理的方法。

if(input$select1 == "V"){

    if(input$select2 =="a"){
        # Here goes reactiveEvent codes and complex stuff

        output$Final1 = renderPrint(subprocessVa1())
        output$Final2 = renderPrint(subprocessVa2())

    } else if(input$select2 == "b"){
        # Here goues reactiveEvents and ObserveEvents and crazy stuff but different

        output$Final1 = renderPrint(subprocessVb1())
        output$Final2 = renderPrint(subprocessVb2())

    } else if(input$select2 == "c"){
        # You get the idea

        output$Final1 = renderPrint(subprocessVc1())
        output$Final2 = renderPrint(subprocessVc2())
    }

} else if(input$select1 == "W"){

    if(input$select2 == "a"){

        # I hope you are getting the idea. this is being written

        output$Final1 = renderPrint(subprocessWa1())
        output$Final2 = renderPrint(subprocessWa2())

    } else if(input$select2 == "b"){
        # Here goues reactiveEvents and ObserveEvents and crazy stuff but different

        output$Final1 = renderPrint(subprocessWb1())
        output$Final2 = renderPrint(subprocessWb2())

    } else if(input$select2 == "c"){

        # You get the idea

        output$Final1 = renderPrint(subprocessWc1())
        output$Final2 = renderPrint(subprocessWc2())
    }

观察到 output$Final1output$Final2 将成为不同的输出,具体取决于所选的过程(作为 selectInputs 的组合) 当然这不能用闪亮来完成。我怎么能继续。使用带有嵌套 ObserveEvents 和嵌套 reactiveEvents 的开关???

请帮忙。

好的,我知道怎么做了。我只需要使用 if() 语句流程。

我最初拥有的是 server 中的一个对象,它可以根据 selectInput()1selectInput()2 的不同组合而具有不同的形式。

我只是创建了与selectInput()的每个组合关联的command()对象, 并且根据输入的组合经历了不同过程(或转换)的感兴趣的对象被写成或多或少的形式:

server = function(input, output,session){

    command = reactive({
            req(input$select1)
            req(input$select2)
            paste0(input$select1,input$select2)
         })

    object1 = eventReactive(input$button{
            df = read.csv(input$file$datapath, etc etc)
        if(command() == "Wa"){

            Wa(df)  # where Wa is a transformation or function of df

        } else if(command() == "Wb"){

            Wb(df) # the next transformation

        } else if( ){   .....   }
    })

    output$trasformed.object = renderTable(object1())
}

感谢@Ben 的帮助。