使用Shiny绘制数据库值

时间:2013-12-10 20:34:22

标签: sql r shiny rodbc

我查看了SQL和RODBC上的许多不同帖子,但出于某种原因,我似乎无法弄明白这一点。我创建了一个闪亮的应用程序。用户将输入选择的日期范围,并且应显示带有查询数据的图表。但是,这不起作用。我已经尝试过编写SQL字符串中的日期和那个WORKS。所以我已经确定了日期没有正确转移到sql字符串的问题。我尝试了paste0(),但认为sprintf()更适合拥有多个值。顺便说一下,我正在查询PI服务器。这是我的代码:

服务器

library(shiny)
library(RODBC)



shinyServer(function(input, output) {

Connection <- odbcConnect(dsn = "PIWHI", believeNRows = FALSE, rows_at_time =1)

x <- reactive({input$range[1]})
y <- reactive({input$range[2]})


query <- sprintf("SELECT time, value
          FROM picomp
          WHERE tag = 'A80100'
          AND time >= DATE('%s')
          AND time <= DATE('%s')", x,y)

LineX <- sqlQuery(WhitingPI, query)


Gravity <- LineX$VALUE
Time <- LineX$TIME

output$den <- renderPlot({plot(Time,Gravity)})


}
)

UI

library(shiny)
library(reshape)

shinyUI(pageWithSidebar(
  # Application title
  headerPanel("Monitoring Tool"),

  sidebarPanel(
   dateRangeInput('range',
                  label = 'Date input: dd-mm-yyyy. Controls start and end of date range input in main panel.',
                  start = Sys.Date()-1, end = Sys.Date(),
                  format = "dd-M-yyyy", startview = 'year', language = 'en', weekstart = 1),

   sliderInput("sigmacoef", "Confidence Level",min = 0, max = 5, value = 2, step =0.5),
   submitButton("Update View")
   ),
  mainPanel(
   plotOutput("den")

  )
    ))

0 个答案:

没有答案