我想为从mysql数据库中提取的数据创建rChart。如ui.R和server.R中所示,创建的ggplot是可见的但不是rChart?任何人都可以解释这里出了什么问题吗?
ui.R
library(shiny)
library("shinyBS", lib.loc="/home/thisa/R/x86_64-pc-linux-gnu-library/3.0")
require("rCharts")
options(RCHART_LIB = 'polycharts')
# Define UI for application that plots random distributions
shinyUI(fluidPage(
# Show a plot of the generated distribution
mainPanel(
fluidRow(
column(width=4,
plotOutput("sales")
),
column(width=8,
showOutput("salesR","polycharts")
)
)
)
))
server.R
library(shiny)
library("DBI", lib.loc="/home/thisa/R/x86_64-pc-linux-gnu-library/3.0")
library("RMySQL", lib.loc="/home/thisa/R/x86_64-pc-linux-gnu-library/3.0")
library("ggplot2", lib.loc="/home/thisa/R/x86_64-pc-linux-gnu-library/3.0")
library("shinyBS", lib.loc="/home/thisa/R/x86_64-pc-linux-gnu-library/3.0")
require("rCharts")
con <- dbConnect(MySQL(),
user="root",password="891208",host="localhost",dbname="openPos")
# Define server logic required to generate and plot a random distribution
shinyServer(function(session,input, output) {
sales_total <- reactive({ "SELECT ospos_sales.sale_time,
CAST(sale_time AS date) AS sale_date, ospos_sales.employee_id,
ospos_sales.sale_id, ospos_sales_items.line,
ospos_sales_items.quantity_purchased,
ospos_sales_items.item_cost_price,
ospos_sales_items.item_unit_price,
ospos_sales_items.discount_percent,
ospos_suppliers.person_id,
ospos_suppliers.company_name,
ospos_items.name, ospos_items.category,
ospos_items.supplier_id,
ospos_items.item_number,
ospos_items.quantity,
ospos_items.reorder_level,
ospos_items.location,
sum(quantity_purchased * item_unit_price-item_unit_price*(discount_percent/100))
AS revenue, sum(quantity_purchased * item_cost_price) AS cost
FROM ospos_sales, ospos_sales_items,
ospos_suppliers, ospos_items
WHERE ospos_sales.sale_id = ospos_sales_items.sale_id
AND ospos_sales_items.item_id = ospos_items.item_id
AND ospos_items.supplier_id = ospos_suppliers.person_id
GROUP BY sale_time"})
salesTotal <- reactive({dbGetQuery(con,sales_total())})
output$sales <- renderPlot
({
p<-ggplot(salesTotal(),
aes_string(x="sale_time",y="revenue"))+geom_point()
print(p)})
output$salesR <- renderChart({
m1 <- rPlot(revenue ~ sale_time, data = salesTotal(),type='point')
return(m1)
})
})