this is my first R Shiny project.and as background I try to make a histogram from data that I take from my Database and use date as it's condition.
this is my code
App.R
library(shiny)
library(RJDBC)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Test Project"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
dateRangeInput('dateRange',
label = 'Molding Date',
start = Sys.Date() - 7, end = Sys.Date()
)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver" , "C:/Microsoft JDBC Driver 6.4 for SQL Server/sqljdbc_6.4/enu/mssql-jdbc-6.4.0.jre8.jar" ,identifier.quote="`")
con <- dbConnect(drv, "jdbc:sqlserver://localhost;databaseName=db1", "user1", "pass", DBMSencoding = "UTF-8")
q1 <- dbGetQuery(con, "SELECT molding_date,thickness FROM table1")
output$distPlot <- renderPlot({
x <- q1
# draw the histogram
hist(x[as.Date(x$molding_date,"%m/%d/%Y") >= min(input$dateRange) & as.Date(x$molding_date,"%m/%d/%Y") <= max(input$dateRange),], col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
and here is my data
molding_date thickness
2018/07/06 10
2018/07/07 20 2018/07/08 10
2018/07/09 9.7
2018/07/09 10
this error always come up when I run the app
Warning: Error in hist.default: 'x' must be numeric
Do I need to parse my thickness data into int before I drawing the histogram?