Unused Arguments

160 views
Skip to first unread message

Harold Doran

unread,
Feb 11, 2016, 2:06:15 PM2/11/16
to Shiny - Web Framework for R
Hello

I am running into the following error with my shiny program:

Error in ssrVerify: unused arguments (f1, f2)

I source in my function ssrVerify() and then at the top to use in the shiny program. This function works perfectly when I run it in the R workspace, but when I run it within the Shiny program it yields the error above.

Below are current minimal server.r and ui.r code that can be dropped in to see how I have set things up. Unfortunately, I cannot post my ssrVerify function or sample data as both of those contain proprietary information; I hope this doesn't prevent problem solving this, though I realize the limitations in not providing it.

When I comment out my ssrVerify() function and replace it with any other function that also makes use of the same data, it works just fine. So, I'm not sure why my function ssrVerify works in the R workspace, but kicks out this error when run within Shiny.

Thanks for any help offered and if there is more information I can provide please let me know.

Harold



options(shiny.maxRequestSize=100*1024^2) 
source('ssrVerify.R')
### Begin server.r
shinyServer(function(input, output, session) {
  
    ###################################################################
# server.r code for SSR Verification
    ###################################################################
  
  filedata1 <- reactive({
    infile <- input$file1
    if (is.null(infile)) return(NULL)      
    read.csv(infile$datapath, header=input$header, sep=input$sep, quote=input$quote)
    })

  filedata2 <- reactive({
    infile <- input$file2
    if (is.null(infile)) return(NULL)      
    read.csv(infile$datapath, header=input$header, sep=input$sep, quote=input$quote)
    })
    
    output$structure1 <- renderPrint({
    input$structure1
    isolate({   
      df1 <- filedata1()
      str(df1)
    })   
    })

    output$structure2 <- renderPrint({
    input$structure2
    isolate({   
      df2 <- filedata2()
      str(df2)
    })   
    })
    
    # reactive expression used so that 'fm' can be passed to other functions
    ssrVerify <- reactive({
    input$ssrVerify
    isolate({   
      f1 <- filedata1()
      f2 <- filedata2()
      #if(is.null(f1)) return(NULL)
      #if(is.null(f2)) return(NULL)
      ssrVerify(f1,f2)
      #foo(f1)
      })
    })
    
    output$ssrVerify <- renderPrint({
    input$ssrVerify
    isolate({   
result <- ssrVerify()
      if (is.null(result)) return(NULL)
     result
    }) 
    })
    
}) # end Program


#### Begin UI
library(markdown)

shinyUI(navbarPage("Toolbar",

tabPanel("Overview",
h1('Online Statistics and Item Response Analysis Tool', align = 'center', style = 'color:blue'),
fluidRow(
column(4,
includeHTML("overview.html")
),
column(4,
includeHTML("data.html")
),
column(4,
includeHTML("methods.html")
)
)
), # end tabpanel

tabPanel("SSR Verification",
  sidebarLayout(
    sidebarPanel(
    
      fileInput('file1', 'Choose SSR File',
            accept=c('text/csv', 
            'text/comma-separated-values,text/plain', '.csv')),
            
     fileInput('file2', 'Choose Score File',
            accept=c('text/csv', 
            'text/comma-separated-values,text/plain', '.csv')),
                         
tags$hr(),
 
h6("Check box if datafile has variable names in first row"),
    checkboxInput('header', 'Header', TRUE),
      
radioButtons('sep', 'Separator',
            c(Comma=',',
            Semicolon=';',
            Tab='\t',
            Pipe ='|'),
            ','),
                   
      radioButtons('quote', 'Quote',
            c(None='',
            'Double Quote'='"',
            'Single Quote'="'"),
            '"'),
        
  actionButton("structure1", "View SSR data structure"),
  actionButton("structure2", "View Score data structure"),
  actionButton("ssrVerify", "Run SSR Verification")
),

      mainPanel(
      verbatimTextOutput('ssrVerify'), 
      verbatimTextOutput('structure1'),
      verbatimTextOutput('structure2')
)
 ) 
) # end tabpanel for SSR Verification
)) # end program

Harold Doran

unread,
Feb 11, 2016, 2:09:34 PM2/11/16
to Shiny - Web Framework for R
One more piece of information, here are the arguments to my function used if this helps

> args(ssrVerify)
function (ssr, scores, scoreFlagsub = TRUE, printRecords = TRUE, 
    uinVar = "UIN_E", scoreFlag = "ScoreFlag_E", capUL = 412, 
    capLL = 284, tol = 1e-04) 

Joe Cheng

unread,
Feb 11, 2016, 2:34:37 PM2/11/16
to Harold Doran, Shiny - Web Framework for R
You overrode your function by calling your reactive expression ssrVerify too. I'd just change the name of the reactive expression.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/bfdf7448-1948-4672-9ad9-cbdf60fd6d04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harold Doran

unread,
Feb 11, 2016, 2:47:07 PM2/11/16
to Shiny - Web Framework for R, harold...@gmail.com
Thank you, Joe. Did this below inside the server.r file, but maybe I'm missing something still as this didn't solve the issue? I commented out the second part, as the program ssrVerify actually writes a set of files to a working directory, so I don't really need anything printed to screen. I just need the files the program outputs.

    # reactive expression used so that 'fm' can be passed to other functions
    ssrVerify1 <- reactive({
    input$ssrVerify
    isolate({   
      f1 <- filedata1()
      f2 <- filedata2()
      #if(is.null(f1)) return(NULL)
      #if(is.null(f2)) return(NULL)
      ssrVerify(f1,f2)
      })
    })
    
    #output$ssrVerify <- renderPrint({
    #input$ssrVerify
    #isolate({ 
    #ssrVerify(f1,f2)  
#result <- ssrVerify()
    #  if (is.null(result)) return(NULL)
    # result
    #}) 
    #})

Joe Cheng

unread,
Feb 11, 2016, 2:53:35 PM2/11/16
to Harold Doran, Shiny - Web Framework for R
This shouldn't be a reactive expression at all, then. You want to do this:

observeEvent(input$ssrVerify, {
       f1 <- filedata1()
      f2 <- filedata2()
      #if(is.null(f1)) return(NULL)
      #if(is.null(f2)) return(NULL)
      ssrVerify(f1,f2)
})

Writing to disk is an action not a calculation. If you want to perform an action, use observe or observeEvent. If you want to do a calculation (i.e. return a value) and there are no side effects like writing to disk, that's the right time to use reactive or eventReactive.

If you're wondering where this little bit of advice is documented, unfortunately, it's not--we're working on it now, though.

Reply all
Reply to author
Forward
0 new messages