Created
May 7, 2013 10:40
-
-
Save ramnathv/5531732 to your computer and use it in GitHub Desktop.
rCharts NVD3 Shiny App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(rCharts) | |
shinyServer(function(input, output) { | |
output$myChart <- renderChart({ | |
hair_eye = as.data.frame(HairEyeColor) | |
p6 <- nPlot(Freq ~ Hair, group = 'Eye', data = subset(hair_eye, Sex == input$gender), | |
type = input$type, dom = 'myChart', width = 800) | |
p6$chart(color = c('brown', 'blue', '#594c26', 'green'), stacked = input$stack) | |
return(p6) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(rCharts) | |
shinyUI(pageWithSidebar( | |
headerPanel("rCharts: Interactive Charts from R | NVD3"), | |
sidebarPanel( | |
selectInput(inputId = "gender", | |
label = "Choose Gender", | |
choices = c("Male", "Female"), | |
selected = "Male"), | |
selectInput(inputId = "type", | |
label = "Choose Chart Type", | |
choices = c("multiBarChart", "multiBarHorizontalChart"), | |
selected = "multiBarChart"), | |
checkboxInput(inputId = "stack", | |
label = strong("Stack Bars?"), | |
value = FALSE) | |
), | |
mainPanel( | |
showOutput("myChart", "nvd3") | |
) | |
)) |
Its funny but it works from a different computer... in both instances, chrome browser. The other apps are fine too. Thanks. No issue here.
Wish I could put this code along side my tomcat web app but cant :(
I don't understand where you get the data? How can I use my own data (eg,csv or excel file)?
May you help me? I'm new in this area. Regards
I'm having trouble implementing a slightly different example where the nplot is a scatterplot that switches between two variables. The plot doesn't appear even if I remove the switch by replacing datasetInput()
with Murder
in server.R.
Any ideas on how I can make this work?
server.R
require(rCharts)
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$crime,
"assault" = Assault,
"murder" = Murder)
})
output$arrestPlot <- renderChart({
w2 <- nPlot(datasetInput() ~ UrbanPop,
data = USArrests,
type = 'scatterChart')
w2$chart(tooltipContent = "#! function(key, x, y, e){
return e.point.row.names
} !#")
w2$set(title = "Water Footprint vs. Protein: California")
w2$xAxis(axisLabel = 'Protein (%)')
w2$yAxis(axisLabel = "Water Footprint: California (L/100g)" )
w2$chart(showControls = F) ## turn off magnify.
return(w2)
})
}
ui.R
require(rCharts)
shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R | NVD3"),
sidebarPanel(
selectInput(inputId = "crime",
label = "Crime:",
choices = c("assault","murder"),
selected = "assault")
),
mainPanel(
showOutput("arrestPlot", "nvd3")
)
))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ramnath, I'm running into some trouble moving a couple of shiny apps with rCharts on to glimmer. As a test case, I just copied this server/ui code and its in a "dummy" application folder (identical code as this): http://glimmer.rstudio.com/vivekpatil/dummy/
Can you please see if you are able to run it? Thanks.