Failed to view variables from select input


#1

Hello, :slight_smile:
I have a problem when I want to view my result of my R script in R shiny. But, I found the problem is the variable in select input doesn't work to get the parameter of my R script. Here is the code of server :

est_rao = source("D:\\Skripsi\\R\\Dari buku Rao\\Estimasi EB turunan satu2 versi 2.R")
boots_rao = source("D:\\Skripsi\\R\\Dari buku Rao\\MSE_boots dari versi2.R")
jackk_rao = source("D:\\Skripsi\\R\\Dari buku Rao\\MSE_jackk dari versi2.R")
est_claire = source("D:\\Skripsi\\R\\Dari jurnal Utah\\Estimasi EB.R")
boots_claire = source("D:\\Skripsi\\R\\Dari jurnal Utah\\MSE_Bootstrap.R")
jackk_claire = source("D:\\Skripsi\\R\\Dari jurnal Utah\\MSE_Jackknife.R")

server = function(input,output,session){
  mydata = eventReactive(input$file1,{
    if(is.null(mydata))
      return(NULL)
    inFile = input$file1
    mydata = read.csv(inFile$datapath, header = input$header, sep =input$sep, dec = input$dec)
    variabel = names(mydata)
    updateSelectizeInput(session,'yi','Jumlah kategori sukses setiap area',choices = variabel) 
    updateSelectizeInput(session, 'ni','Jumlah Sampel setiap area',choices = variabel)
    updateSelectizeInput(session ,'maty','Proporsi (penduga langsung)',choices = variabel)
    updateSelectizeInput(session, 'se','Standart Error',choices = variabel)
    
    mydata
  })
  
  output$table.output = renderTable({
    mydata()
  })
  
  mydata1 = eventReactive(input$file2,{
    if(is.null(mydata1))
      return(NULL)
    inFile1 = input$file2
    mydata1 = read.csv(inFile1$datapath, header = input$header1, sep = input$sep1, dec = input$dec1)
    variabel1 = names(mydata1)
    updateSelectizeInput(session ,'yruta','Kategori setiap ruta (perlu diisi jika menggunakan bootstrap)',choices = variabel1)
    updateSelectizeInput(session ,'koderuta','Kode area setiap ruta (perlu diisi jika menggunakan bootsrap)',choices = variabel1)
    
    mydata1
  })
  
  output$table.output1 = renderTable({
    mydata1()
  })
  
  est = eventReactive(input$test,{
    area = mydata()
    ruta = mydata1()
    maty = mydata[,input$maty]
    yi = mydata[,input$yi]
    ni = mydata[,input$ni]
    yruta = mydata1[,input$yruta]
    koderuta = mydata1[,input$koderuta]
    ############RAO##################
    if(input$metode == 1){
      #moment
      if(input$alfa_beta == 1){
        #est_naive
        if(input$MSE == 1){
          estimasi = est_rao$value(maty = maty,yi = yi,ni = ni)
        } else {
          #est_jackk
          if(input$MSE ==2){
            estimasi = jackk_rao$value(maty = maty,ni = ni,yi = yi)
          }else{
            #est_boots
            if(input$MSE ==3){
              estimasi = boots_rao$value(maty = maty,ni = ni,yi = yi,yRuta = yruta,kodeRuta = koderuta,B = 10)
            }
          }
        }
      } else {
        if(input$MSE ==1){
          estimasi = est_rao$value(maty = maty,yi = yi,ni = ni,method = "NR")
        } else {
          if(input$MSE ==2){
            estimasi = jackk_rao$value(maty = maty,ni = ni,yi = yi,method = "NR")
          }else{
            if(input$MSE == 3){
              estimasi = boots_rao$value(maty = maty,ni = ni,yi = yi,yRuta = yruta,kodeRuta = koderuta,B = 10,method = "NR")
            }
          }
        }
      }
    } else{
      ############Claire##################
      if(input$alfa_beta == 1){
        if(input$MSE == 1){
          estimasi = est_claire$value(maty = maty,yi = yi,ni = ni)
        } else {
          if(input$MSE == 2){
            estimasi = jackk_claire$value(maty = maty,yi = yi,ni = ni)
          }else{
            if(input$MSE == 3){
              estimasi = boots_claire$value(ni = ni,yi = yi,maty = maty,yRuta = yruta,kodeRuta = koderuta,B = 10)
            }
          }
        }
      } else {
        if(input$MSE == 1){
          estimasi = est_claire$value(maty = maty,yi = yi,ni = ni,method = "NR")
        } else {
          if(input$MSE == 2){
            estimasi = jackk_claire$value(maty = maty,yi = yi,ni = ni,method = "NR")
          }else{
            if(input$MSE == 3){
              estimasi = boots_claire$value(ni = ni,yi = yi,maty = maty,yRuta = yruta,kodeRuta = koderuta,B = 10,method = "NR")
            }
          }
        }
      }
    }
    estimasi
  })
  
  output$hasil <- renderPrint(
    est()
  )
  
  
  output$plothasil = renderPlot({
    plot(mydata())
  })
  
}


and here is the code of UI :
ui = fluidPage(
  titlePanel("Empirical Bayes Beta-Binomial with No Covariate in Small Area Estimation"),

  navbarPage("Menu",
             tabPanel("Estimasi",
                      sidebarLayout(
                        sidebarPanel(

                          selectInput(inputId = "metode", label = "Metode menurut", choices = list("Rao"=1,"Claire"=2), selected = 1),
                          selectInput(inputId = "alfa_beta", label = "Estimasi parameter alfa dan beta", choices = list("Moment"=1,"Newton-Raphson"=2), selected = 1),
                          selectInput(inputId = "MSE", label = "Metode Estimasi", choices = list("Estimasi dengan MSE naive"=1, "Estimasi dengan MSE jackknife"=2,"Estimasi dengan MSE bootstrap"=3), selected = 1),
                          actionButton("test","Test")
                        ),
                        mainPanel(
                          plotOutput("plothasil"),
                          verbatimTextOutput("hasil")
                        )
                      )
             ),

             tabPanel("Upload Data",
                      tabsetPanel(
                        tabPanel("Data Utama",
                                 sidebarLayout(
                                   sidebarPanel(
                                     fileInput("file1","Input data setiap area",
                                               accept = c("text/csv",
                                                          "text/comma-separated-values,text/plain",
                                                          ".csv")),

                                     tags$hr(),
                                     checkboxInput('header','Header',TRUE),

                                     radioButtons('sep','Separator',c(Comma = ',',
                                                                      Semicolon =';'),','),

                                     radioButtons('dec','Decimal seperator',
                                                  c('comma' = ",",
                                                    'punktum' = "."), '.'),

                                     selectizeInput('yi','Jumlah kategori sukses setiap area',choices = NULL),
                                     selectizeInput('ni','Jumlah Sampel setiap area',choices = NULL),
                                     selectizeInput('maty','Proporsi (penduga langsung)',choices = NULL),
                                     selectizeInput('se','Standart Error',choices = NULL)

                                   ),
                                   mainPanel(
                                     tableOutput("table.output")
                                   )
                                 )
                        ),

                        tabPanel("Data Tambahan",
                                 sidebarLayout(
                                   sidebarPanel(
                                     fileInput("file2","Input data setiap ruta(diperlukan untuk estimasi MSE dengan Bootstrap)",
                                               accept = c("csv","comma-separated-values,text/plain",
                                                          ".csv")),

                                     tags$hr(),

                                     checkboxInput('header1','Header',TRUE),

                                     radioButtons('sep1','Separator',c(Comma = ',',Semicolon =';',
                                                                       Tab = '\t'),','),

                                     radioButtons('dec1','Decimal seperator',c('comma' = ",",
                                                                               'punktum' = "."), '.'),

                                     selectizeInput('yruta','Kategori setiap ruta (perlu diisi jika menggunakan bootstrap)',choices = NULL),
                                     selectizeInput('koderuta','Kode area setiap ruta (perlu diisi jika menggunakan bootsrap)',choices = NULL)

                                   ),
                                   mainPanel(
                                     tableOutput("table.output1")
                                   )
                                 )
                        )
                      )
             )



  )
)

Can you help me please what is the wrong in the code ? :blush:
Thank you