I've been trying to utilize shiny to create several visualizations for several different classes of data. Last night I was able to subset data but I do not know how to switch plot types with this data. I have the following data frame:
Hours<-c(2,3,4,2,1,1,3)
Project<-c("a","b","b","a","a","b","a")
cd=data.frame(Project,Hours)
server.R
library(shiny)
library(ggplot2)
library(lattice)
# Define shiny server
shinyServer(function(input, output) {
#Simple test plot
pdata=subset(cd, Project==input$proj)
plotType <- function(x, type) {
switch(type,
A = hist(x),
B = barplot(x),
C = pie(x))
}
output$testPlot <- renderPlot({
plotType(pdata, input$pType)
})
})
ui.R
library(shiny)
ulist=levels(cd$Project)
names(ulist) = ulist
# Sidebar with a slider input for the number of bins
shinyUI(pageWithSidebar(
# Application title
headerPanel("Project Data"),
sidebarPanel(
#select project
selectInput("proj", "Project:",ulist)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("testPlot")
)))
I'd like to incorporate the following code from jdharrison to the ui file:
ui = bootstrapPage(
radioButtons("pType", "Choose plot type:",
list("A", "B", "C")),
plotOutput('plot')
The following is a link to his post which I'm trying to incorporate: create plots based on radio button selection R Shiny