Skip to content

Commit

Permalink
update shiny app and blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnathv committed Apr 12, 2013
1 parent a575d4e commit 378d96e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
15 changes: 9 additions & 6 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ p1$layer2(x = "countrycode", y = "value", color = 'gender',
data = men, type = 'point', size = list(const = 3))
# Step 4. format the x and y axis labels
p1$guides(x = list(ticks = unique(men$CountryCode)))
p1$guides(x = list(title = "", ticks = unique(men$countrycode)))
p1$guides(y = list(title = "", max = 18))
# Step 5. set the width and height of the plot and attach it to the dom
p1$addParams(width = 600, height = 300, dom = 'chart1')
p1$addParams(width = 600, height = 300, dom = 'chart1',
title = "Percentage of Employed who are Senior Managers")
# Step 6. print the chart (just type p1 if you are using it in your R console)
p1$printChart()
Expand Down Expand Up @@ -161,20 +162,22 @@ shinyServer(function(input, output) {
men <- subset(dat2m, gender == "Men" & year == YEAR)
women <- subset(dat2m, gender == "Women" & year == YEAR)
p1 <- rPlot(x = list(var = "countrycode", sort = "value"), y = "value",
color = 'gender', data = women, type = 'bar')
color = 'gender', data = women, type = 'bar')
p1$layer2(x = "countrycode", y = "value", color = 'gender',
data = men, type = 'point', size = list(const = 3))
p1$addParams(height = 300, dom = 'chart1')
p1$guides(x = list(ticks = unique(men$CountryCode)))
p1$addParams(height = 300, dom = 'chart1',
title = "Percentage of Employed who are Senior Managers")
p1$guides(x = list(title = "", ticks = unique(men$countrycode)))
p1$guides(y = list(title = "", max = 18))
return(p1)
})
output$chart2 <- renderChart({
COUNTRY = input$country
country = subset(dat2m, country == COUNTRY)
p2 <- rPlot(value ~ year, color = 'gender', type = 'line', data = country)
p2$addParams(height = 300, dom = 'chart2')
p2$guides(y = list(min = 0, title = ""))
p2$guides(y = list(title = ""))
p2$addParams(height = 300, dom = 'chart2')
return(p2)
})
})
Expand Down
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ <h3>Bar Plot</h3>
data = men, type = &#39;point&#39;, size = list(const = 3))

# Step 4. format the x and y axis labels
p1$guides(x = list(ticks = unique(men$CountryCode)))
p1$guides(x = list(title = &quot;&quot;, ticks = unique(men$countrycode)))
p1$guides(y = list(title = &quot;&quot;, max = 18))

# Step 5. set the width and height of the plot and attach it to the dom
p1$addParams(width = 600, height = 300, dom = &#39;chart1&#39;)
p1$addParams(width = 600, height = 300, dom = &#39;chart1&#39;,
title = &quot;Percentage of Employed who are Senior Managers&quot;)

# Step 6. print the chart (just type p1 if you are using it in your R console)
p1$printChart()
</code></pre>

<script type='text/javascript'>
var chartParams = {"dom":"chart1","width":600,"height":300,"layers":[{"x":{"var":"countrycode","sort":"value"},"y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women"],"value":[4.4,3,4.7,2.8,1.6,6.5,3.4,6.2,3.2,2.4,5,7.5,5.3,2.4,2.4,4.7,4.3,5.2,4.3,3.7,6.9,3.3,4,5.7,7.5]},"color":"gender","type":"bar"},{"x":"countrycode","y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men"],"value":[7.7,6.8,9.2,6.2,3.8,11.6,6.8,8.6,6.4,5.4,6.3,10.4,9.3,5,5.7,9.6,8.5,6.8,7.8,6.5,9.4,6.3,6.8,9.6,12.5]},"color":"gender","type":"point","size":{"const":3}}],"facet":[],"guides":{"x":{"ticks":null},"y":{"title":"","max":18}},"coord":[]}
var chartParams = {"dom":"chart1","width":600,"height":300,"layers":[{"x":{"var":"countrycode","sort":"value"},"y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women"],"value":[4.4,3,4.7,2.8,1.6,6.5,3.4,6.2,3.2,2.4,5,7.5,5.3,2.4,2.4,4.7,4.3,5.2,4.3,3.7,6.9,3.3,4,5.7,7.5]},"color":"gender","type":"bar"},{"x":"countrycode","y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men"],"value":[7.7,6.8,9.2,6.2,3.8,11.6,6.8,8.6,6.4,5.4,6.3,10.4,9.3,5,5.7,9.6,8.5,6.8,7.8,6.5,9.4,6.3,6.8,9.6,12.5]},"color":"gender","type":"point","size":{"const":3}}],"facet":[],"guides":{"x":{"title":"","ticks":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"]},"y":{"title":"","max":18}},"coord":[],"title":"Percentage of Employed who are Senior Managers"}
_.each(chartParams.layers, function(el){el.data = polyjs.data(el.data)})
polyjs.chart(chartParams);
</script>
Expand Down
7 changes: 4 additions & 3 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,19 @@ p1$layer2(x = "countrycode", y = "value", color = 'gender',
data = men, type = 'point', size = list(const = 3))

# Step 4. format the x and y axis labels
p1$guides(x = list(ticks = unique(men$CountryCode)))
p1$guides(x = list(title = "", ticks = unique(men$countrycode)))
p1$guides(y = list(title = "", max = 18))

# Step 5. set the width and height of the plot and attach it to the dom
p1$addParams(width = 600, height = 300, dom = 'chart1')
p1$addParams(width = 600, height = 300, dom = 'chart1',
title = "Percentage of Employed who are Senior Managers")

# Step 6. print the chart (just type p1 if you are using it in your R console)
p1$printChart()
```

<script type='text/javascript'>
var chartParams = {"dom":"chart1","width":600,"height":300,"layers":[{"x":{"var":"countrycode","sort":"value"},"y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women"],"value":[4.4,3,4.7,2.8,1.6,6.5,3.4,6.2,3.2,2.4,5,7.5,5.3,2.4,2.4,4.7,4.3,5.2,4.3,3.7,6.9,3.3,4,5.7,7.5]},"color":"gender","type":"bar"},{"x":"countrycode","y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men"],"value":[7.7,6.8,9.2,6.2,3.8,11.6,6.8,8.6,6.4,5.4,6.3,10.4,9.3,5,5.7,9.6,8.5,6.8,7.8,6.5,9.4,6.3,6.8,9.6,12.5]},"color":"gender","type":"point","size":{"const":3}}],"facet":[],"guides":{"x":{"ticks":null},"y":{"title":"","max":18}},"coord":[]}
var chartParams = {"dom":"chart1","width":600,"height":300,"layers":[{"x":{"var":"countrycode","sort":"value"},"y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women","Women"],"value":[4.4,3,4.7,2.8,1.6,6.5,3.4,6.2,3.2,2.4,5,7.5,5.3,2.4,2.4,4.7,4.3,5.2,4.3,3.7,6.9,3.3,4,5.7,7.5]},"color":"gender","type":"bar"},{"x":"countrycode","y":"value","data":{"country":["OECD","Austria","Belgium","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Luxembourg","Netherlands","Norway","Poland","Portugal","Slovak Republic","Slovenia","Spain","Sweden","Switzerland","United Kingdom"],"countrycode":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"],"year":[2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011,2011],"id":[1,3,4,7,8,9,10,11,12,13,14,15,16,18,21,23,25,26,27,28,29,30,31,32,34],"gender":["Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men","Men"],"value":[7.7,6.8,9.2,6.2,3.8,11.6,6.8,8.6,6.4,5.4,6.3,10.4,9.3,5,5.7,9.6,8.5,6.8,7.8,6.5,9.4,6.3,6.8,9.6,12.5]},"color":"gender","type":"point","size":{"const":3}}],"facet":[],"guides":{"x":{"title":"","ticks":["OECD","AUT","BEL","CZE","DNK","EST","FIN","FRA","DEU","GRC","HUN","ISL","IRL","ITA","LUX","NLD","NOR","POL","PRT","SVK","SVN","ESP","SWE","CHE","GBR"]},"y":{"title":"","max":18}},"coord":[],"title":"Percentage of Employed who are Senior Managers"}
_.each(chartParams.layers, function(el){el.data = polyjs.data(el.data)})
polyjs.chart(chartParams);
</script>
Expand Down
Binary file modified payload.RData
Binary file not shown.
10 changes: 6 additions & 4 deletions rChartOECD/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ shinyServer(function(input, output) {
men <- subset(dat2m, gender == "Men" & year == YEAR)
women <- subset(dat2m, gender == "Women" & year == YEAR)
p1 <- rPlot(x = list(var = "countrycode", sort = "value"), y = "value",
color = 'gender', data = women, type = 'bar')
color = 'gender', data = women, type = 'bar')
p1$layer2(x = "countrycode", y = "value", color = 'gender',
data = men, type = 'point', size = list(const = 3))
p1$addParams(height = 300, dom = 'chart1')
p1$guides(x = list(ticks = unique(men$CountryCode)))
p1$addParams(height = 300, dom = 'chart1',
title = "Percentage of Employed who are Senior Managers")
p1$guides(x = list(title = "", ticks = unique(men$countrycode)))
p1$guides(y = list(title = "", max = 18))
return(p1)
})
output$chart2 <- renderChart({
COUNTRY = input$country
country = subset(dat2m, country == COUNTRY)
p2 <- rPlot(value ~ year, color = 'gender', type = 'line', data = country)
p2$addParams(height = 300, dom = 'chart2')
p2$guides(y = list(min = 0, title = ""))
p2$guides(y = list(title = ""))
p2$addParams(height = 300, dom = 'chart2')
return(p2)
})
})

0 comments on commit 378d96e

Please sign in to comment.