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)