我正在尝试为直方图创建一个闪亮的应用程序,以显示最近13个月的数据。我想我对input$colname
中aes()
ggplot()
# required library
library(shiny)
library(ggplot2)
library(dplyr)
library(scales)
library(lubridate)
# function to calculate first day of last month;
endF <- function(x) {
as.Date(format(x, "%Y-%m-01"))
}
startF <- function(x) {
as.Date(format(x - months(6), "%Y-%m-01"))
}
ui <- fluidPage(
dateRangeInput(
"Range",
"Date range:",
start = as.date(startF(startF(Sys.Date()))),
end = as.date(endF(endF(Sys.Date()) - 1)),
#format = "mm/dd/yyyy",
separator = " - "
),
plotOutput("hist"))
# Read .csv files
TotalIncident <- read.csv(file = "TotalIncidents.csv", head = TRUE, sep = ",")
# create Range as date
TotalIncident$Range <-as.Date((TotalIncident$DateRange), format = "%Y-%m-%d")
# remove unnecessary value
TotalIncident1 <- TotalIncident[c(-1)]
# rolling data for 13 months;
Finaldata <-reactive({TotalIncident1[TotalIncident1$Range >= input$RangeInput[1] &
TotalIncident1$Range <= input$RangeInput[2],]})
# Define a server for the Shiny app
server <- function(input, output) {
output$hist <- renderPlot({
p <- ggplot(data = Finaldata(),aes(x = Range,
y = Number.of.Incidents)) +
geom_bar(stat = "identity", fill = "blue") +
scale_x_date(
date_breaks = "1 month",
labels = date_format("%b %y"),
expand = c(0, 0)) +
ylab("Total Incidents") + xlab("Mon YY") +
geom_text(aes(label = Number.of.Incidents),
size = 3,hjust = 0.5,vjust = 2) +
#theme for backgroud
theme_bw() +
theme(plot.background = element_blank(),
panel.grid.major = element_blank() ,
panel.grid.minor = element_blank()) +
theme(panel.border = element_blank()) +
theme(axis.line = element_line(color = "black", size = "2"))
})
}
shinyApp(ui = ui, server = server)
的{{1}}感到震惊
gem 'devise', '~> 4.1.1'
答案 0 :(得分:0)
最后我做到了。我对被动部分的逻辑是错误的。在响应式语句中定义Finaldata并创建Passdata是关键。希望它对其他用户有所帮助。 有用的链接: http://chrisbeeley.net/website/shinytalk/googleAnalytics.html
memcached:
class: Memcached
calls:
-[addServers,[%memcached.servers%]]
memcached.servers:
- { host: 127.0.0.1, port: 11211 }
Parameter "calls" must be an array for service "memcached" in
...Resources/config/services.yml. Check your YAML syntax
library(shiny)
library(ggplot2)
library(dplyr)
library(plyr)
library(scales)
library(lubridate)
TotalIncident <-read.csv(file = "TotalIncidents.csv", head = TRUE, sep = ",")
TotalIncident$Range <-as.Date((TotalIncident$DateRange), format = "%Y-%m-%d")
#output图;
TotalIncident1 <- TotalIncident[c(-1)]
Dates <- as.Date(TotalIncident$DateRange,format="%Y-%m-%d")
minval <- min(Dates)
maxval <- max(Dates)
shinyApp(ui = ui,server = server)