Skip to content

Instantly share code, notes, and snippets.

@kohske
Created January 24, 2013 08:21
Show Gist options
  • Select an option

  • Save kohske/4618680 to your computer and use it in GitHub Desktop.

Select an option

Save kohske/4618680 to your computer and use it in GitHub Desktop.
library(XML)
# 負荷軽減のため
if (length(dir(".", "^data.Rda$")) == 0) {
data <- xmlToDataFrame("http://www3.city.sabae.fukui.jp/xml/population/population.xml",
stringsAsFactors=FALSE,
colClasses=c("integer","integer","character",
"numeric","numeric","numeric",
"numeric","character"))
save("data", file = "data.Rda")
} else {
load("data.Rda")
}
library(shiny)
library(ggplot2)
library(ggthemes)
source('load_data.R')
# Define server logic required to plot various variables against mpg
shinyServer(function(input, output) {
output$main_plot <- reactivePlot(function() {
ge <- switch(input$Geom,
"点" = geom_point(),
"線" = geom_line(),
"点と線" = list(geom_line(), geom_point()),
"棒" = geom_bar(aes_string(fill = input$Color), stat = "identity"),
"エリア" = geom_area(aes(colour = NULL)))
p <- ggplot(data, aes_string(x = input$X, y = input$Y, colour = input$Color)) + ge + theme_wsj()
print(p)
})
})
library(shiny)
source('load_data.R')
# UIの定義
shinyUI(
pageWithSidebar(
headerPanel("鯖江市のXMLでシャイニー!!"),
sidebarPanel(
p("データは",
a("鯖江市のオープンデータ化", href = "http://www.city.sabae.fukui.jp/pageview.html?id=11552"),
"プロジェクトよりお借りしています。"),
p("データの読み込みは",
a("奥村先生の記事", href = "http://oku.edu.mie-u.ac.jp/~okumura/stat/xml.html"),
"を使わせて頂きました。"),
p("なお、サーバ負荷軽減のため、ページ読み込み時にデータのダウンロードは行なっていませんが、リアルタイムに変化するようなデータの場合は、その変化を反映することも可能です。"),
selectInput("X", "X軸の列:", choices = names(data)),
selectInput("Y", "Y軸の列:", choices = names(data)),
selectInput("Color", "色の列:", choices = names(data)),
selectInput("Geom", "グラフの種類:", choices = c("点", "線", "点と線", "棒", "エリア"))
),
mainPanel(
plotOutput("main_plot")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment