一個訪問mysql 數據庫的 shiny 項目

ui.R


library(shiny)


shinyUI(pageWithSidebar(
  
  # Application title
  headerPanel("New Application"),
  
  # Sidebar with a slider input for number of observations
  sidebarPanel(
    sliderInput("obs", 
                "Number of observations:", 
                min = 1, 
                max = 90, 
                value = 10)
  ),
  
  # Show a plot of the generated distribution
  mainPanel(
    plotOutput("distPlot")
  )
))


server.R


library(shiny)
library(RMySQL)
con<-dbConnect(MySQL(),group="kettle")
mydata<-dbReadTable(con,"sellStatic")
mydata
myvars<-c("goodsID","goodsName","sellCount")
newdata<-mydata[myvars]
myvars
goodsName<-newdata$goodsName
sellCount<-newdata$sellCount
goodsName
sellCount
mydata<-data.frame(goodsName,sellCount)


shinyServer(function(input, output) {
   
  
  output$distPlot <- renderPlot({
     
    # generate and plot an rnorm distribution with the requested
    # number of observations
    
    newdata<-mydata[1:input$obs,]
    barplot(newdata$sellCount,names.arg=newdata$goodsName)
    
  })
  
})

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章