getting unused arguments (input = list(, TRUE, function (x) ) in R

getting unused arguments (input = list(, TRUE, function (x) ) in R



# Demo dateInput()

# Load required packages
library(shiny)

ui <- fluidPage(
  h5("R Shiny Demo - dateInput widget"),
  hr(),
  
  # add a date input widget
  dateInput("date",  # Input ID
            
            label="Date Input", # label
            # use below to show the calendar icon inline
            # label = HTML("<i class='glyphicon glyphicon-calendar'></i> Date Input"),
            
            value = Sys.Date(), # date value that shows up initially
            
            min = Sys.Date() - 10,  # set the minimin date
            
            max = Sys.Date() + 10, # set the maximum date
            
            width = "100px", # set the width of widget
            
            format="mm/dd/yy"), # set the format (default is yyyy-mm-dd)
  textOutput("seldate")
)



shinyServer( function(input, output, session) {
  
  
  library(RODBC)
  library(ggplot2)
  library(shiny)
  dbhandle <- odbcDriverConnect('driver={SQL Server};server=xxx\\yyy;database=trade;trusted_connection=true')
  
  # Render text function to output the date from server to ui
  output$plot2 <- reactive ({
    #paste("Selected Date is ", input$date)
    # input$date # this will not output the date in correct format. 
    # Convert to character before using in render function as.character(input$date)
    # as.character(input$date) # to exclusively convert date to character for printing to retain the date format
    # match the date format to the format in input date widget. Use the format() to change the date format
    # paste("Selected Date is ", format(input$date, "%m/%d/%y"))
    
    dbGetQuery (dbhandle, statement =paste("select isin, sum(MarketValue)/100000000 as MV from Position
                        where date in (',input$date,')
                        and CUSIP in ('BRS28U2388')
                        group by CUSIP
                        ;")
                
    )
    
  })
  
  
         
                  
                  
     output$main_plot <- renderPlot ({
      
      ggplot(currTableDF, aes(isin,MV, color = "red", fill = "red")) + geom_bar(stat = "identity") 
      
      })
  
})


shinyApp(ui, shinyServer)
 

Hi,

The error stems from an error in your definition of the server function

shinyServer( function(input, output, session) { 
  ...
})

#Should be
shinyServer <- function(input, output, session) { 
  ...
}

Grtz,
PJ

Thank you Pieterjanvc. No errors. Its not going ahead it is stuck at
"Listening on http://127.0.0.1:6334"

Could you elaborate on what do you mean by "It's not going ahead"?, the message you are showing indicates that shiny server is running and waiting for clients.

Hi andresrcs, you are right. It is listening to receive the input as a date and then use it to pass in the SQL query...when I select the date from the date widget I'm expecting it to go ahead and fore the query and plot the chart...but nothing happens after I select the date.

Maybe is because you are using paste() incorrectly, you have to separate the text strings from the other objects you want to "paste" together, see this example.

input_date <- "2019-07-31"
paste("select isin, sum(MarketValue)/100000000 as MV from Position
where date in (",input_date,")
and CUSIP in ('BRS28U2388')
group by CUSIP;")
#> [1] "select isin, sum(MarketValue)/100000000 as MV from Position\nwhere date in ( 2019-07-31 )\nand CUSIP in ('BRS28U2388')\ngroup by CUSIP;"

It is not working still.
The query is :
paste("select CUSIP, sum(MarketValue)/100000000 as MV from Position
where date in (",input_date,")
and CUSIP in ('BRS28U2388')
group by CUSIP;")

The example I gave you was illustrative only, you can't just copy and paste the code (it is not going to work) you have to adapt it to your context so it can produce a valid sql query, if you need more specific help, please provide a minimal reproducible example (reprex) illustrating your issue. Have a look at this guide, to see how to create one for a shiny app

Thanks Andresrcs. Below is the complete Code (hid the database connection). The issue i'm facing is when i select the date (which is the user input) i expect the query to run and plot it. If I run the same in R and not R Shiny it works fine (meaning it connects to the D/B pulls the data through the query and plots the chart. But in R Shiny after taking the user input i dont see it running the query and plotting the chart. Have been stuck here for a long time. Thanks for your help so far.

library(shiny)

ui <- fluidPage(
  h5("R Shiny Demo - dateInput widget"),
  hr(),
  

  dateInput("date",  # Input ID
            
            label="Date Input", # label
            # use below to show the calendar icon inline
            # label = HTML("<i class='glyphicon glyphicon-calendar'></i> Date Input"),
            
            value = Sys.Date(), # date value that shows up initially
            
            min = Sys.Date() - 10,  # set the minimin date
            
            max = Sys.Date() + 10, # set the maximum date
            
            width = "100px", # set the width of widget
            
            format="yyyy-mm-dd"), # set the format (default is yyyy-mm-dd)
  textOutput("seldate")
)



shinyServer <- function(input, output, session) {
  
  
  library(RODBC)
  library(ggplot2)
  library(shiny)
  dbhandle <- odbcDriverConnect('driver={SQL Server};server=xxxx\\xxxx;database=xxxx;trusted_connection=true')
  

  output$plot2 <- reactive ({
     
    currTableSQL<-paste("select CUSIP, sum(MarketValue)/100000000 as MV from dbo.Position
                        where _FILEDATE = '",input$date,"'
                        and CUSIP in ('BRS28U233','B0A09Z738','BSR4XWWC3','BSR21JQP9','BRS3ZWL36','BSR4JTZB5')
                        group by CUSIP
                        ;")
    currTableDF<-sqlQuery(dbhandle,currTableSQL)
    
    
  })
  
   output$main_plot <- renderPlot ({
   ggplot(currTableDF, aes(CUSIP,MV, color = "red", fill = "red")) + geom_bar(stat = "identity") 
  
      })
  
 

}


shinyApp(ui, shinyServer)

You are not including an output for the plot in your UI function i.e. plotOutput() Does, this work for you?

library(shiny)
library(RODBC)
library(ggplot2)

ui <- fluidPage(
    h5("R Shiny Demo - dateInput widget"),
    hr(),
    dateInput("date", 
              label="Date Input",
              value = Sys.Date(), 
              min = Sys.Date() - 10, 
              max = Sys.Date() + 10,
              width = "100px", 
              format="yyyy-mm-dd"),
    plotOutput("main_plot")
)

shinyServer <- function(input, output, session) {
    
    dbhandle <- odbcDriverConnect('driver={SQL Server};server=xxxx\\xxxx;database=xxxx;trusted_connection=true')
    
    output$main_plot <- renderPlot ({
        currTableSQL <- paste("select CUSIP, sum(MarketValue)/100000000 as MV from dbo.Position
                        where _FILEDATE = '",input$date,"'
                        and CUSIP in ('BRS28U233','B0A09Z738','BSR4XWWC3','BSR21JQP9','BRS3ZWL36','BSR4JTZB5')
                        group by CUSIP
                        ;")
        currTableDF <- sqlQuery(dbhandle,currTableSQL)
        
        ggplot(currTableDF, aes(CUSIP,MV, color = "red", fill = "red")) +
            geom_col()
    })
}

shinyApp(ui, shinyServer)

Thank you so much Andresrcs. I can see the plot now, but when i change the date the plot doesnt change which means its not re-firing the query. Am i missing something here?

If you are following the pattern of the example, that shouldn't be the case, It is hard to know what could be your problem since we don't have access to your database.