R блестящий Ошибка: объект «вход» не найден, когда используется в EventReactive и Desctools - PullRequest
0 голосов
/ 04 декабря 2018

Я знаю, что это может быть дублировано, и я искал несколько вопросов, с которыми похож, но я до сих пор не могу найти, почему мой код не работает.Ошибка возникает, когда два входных источника компилируются в часть eventReactive .

Мой код ошибки выглядит следующим образом:

library(shiny)
library(rio)
library(DescTools)

options(shiny.maxRequestSize=500*1024^2,shiny.usecairo = FALSE)

ui <- fluidPage(

    titlePanel("See the file table"),
    fluidRow(
        column(4,
               fileInput("theFile","upload your file")
        ),
        column(4,
               radioButtons("encode", "encoding way",
                            choices = c("Default" = "default",
                                        "UTF-8" = "utf_8"),selected = "default")
        ),
        column(4,
               uiOutput("a_input")
        ),
        column(4,
               uiOutput("b_input")
        ),
        column(4,
               actionButton("choice3", "Show two variables comparing")
        ),
        column(12,
               verbatimTextOutput("console_comp")
        ),
        column(12,
               plotOutput("plot_Desc_comp")
        )
    )

)
server <- function(input,output, session){

    allData <- reactive({
        theFile <- input$theFile
        req(input$theFile)

        # Changes in read.table 
        if(input$encode == "default"){
            df <- import(theFile$datapath)  
        } else{
            df <- import(theFile$datapath,encoding = "UTF-8")
            return(df)
        }
    })

    output$a_input <- renderUI({
        cn <- colnames(allData())
        selectInput("a_input", "Select A variable to compare with Desc", 
                    choices  = cn,
                    size=10,
                    multiple=F, selectize=FALSE)
    })

    output$b_input <- renderUI({
        cn <- colnames(allData())
        selectInput("b_input", "Select B variable to compare with Desc", 
                    choices  = cn,
                    size=10,
                    multiple=F, selectize=FALSE)
    })


    data_Desc_a <- eventReactive(input$choice3, {
        req(allData())
        dat <- allData()
        dat[,input$a_input, drop = FALSE]
    })

    data_Desc_b <- eventReactive(input$choice3, {
        req(allData())
        dat <- allData()
        dat[,input$b_input, drop = FALSE]
    })

    output$console_comp <-  renderPrint({
        dat <- allData()
        var_a <- data_Desc_a()
        var_b <- data_Desc_b()
        mylist2 <- Desc(var_a ~ var_b, dat)
        print(mylist2)
    })

    output$plot_Desc_comp <-  renderPlot({
        dat <- allData()
        var_a <- data_Desc_a()
        var_b <- data_Desc_b()
        mylist2 <- Desc(var_a ~ var_b, dat)
        plot(mylist2)
    })

}
shinyApp(ui, server)

Код ошибки возникает, когда я хочу нажать кнопку «Показать сравнение двух переменных» после того, как я загрузил один файл и выбрал два параметра, иошибка, подобная этой:

неиспользуемые аргументы (var_a ~ var_b, dat)

Даже если я просто использую один источник , это может помочь.

Мой рабочий код выглядит так:

ui <- fluidPage(

    titlePanel("See the file table"),
    fluidRow(
        column(6,
               fileInput("theFile","upload your file")
        ),
        column(6,
               radioButtons("encode", "encoding way",
                            choices = c("Default" = "default",
                                        "UTF-8" = "utf_8"),selected = "default")
        ),
        column(8,
               uiOutput("colToDesc")
        ),
        column(4,
               actionButton("choice2", "Show variables Desc")
        ),
        column(12,
               verbatimTextOutput("console")
        ),
        column(12,
               plotOutput("plot_Desc")
        )
    )

)
server <- function(input,output, session){

    allData <- reactive({
        theFile <- input$theFile
        req(input$theFile)

        # Changes in read.table 
        if(input$encode == "default"){
            df <- import(theFile$datapath)  
        } else{
            df <- import(theFile$datapath,encoding = "UTF-8")
            return(df)
        }
    })


    output$colToDesc <- renderUI({
        cn <- colnames(allData())
        selectInput("colToDesc", "Select variable to Desc", 
                    choices  = cn,
                    size=10,
                    multiple=T, selectize=FALSE)
    }) 

    data_Desc <- eventReactive(input$choice2, {

        req(allData())
        dat <- allData()
        dat[,input$colToDesc, drop = FALSE]
    })

    output$console <-  renderPrint({
        variables <- data_Desc()
        mylist <- Desc(variables,main = names(variables))
        print(mylist)
    })

    output$plot_Desc <-  renderPlot({
        variables <- data_Desc()
        mylist <- Desc(variables,main = names(variables))
        plot(mylist)
    })   
}

И я могу быть уверен, что функция Desc из пакета DescTools может работать так:

Desc(temp[,91]~temp[,5],temp)

Так что не так с моим кодом ошибки.

...