Question

I'm trying to create a shiny app that plots data as a bubble chart. The problem I'm having is the subsetting. The user is able to choose the subset of data with some of the inputs. Below is some of the code I have. I keep getting this error: Error in data.frame(NA= NULL, var6 = c(1.95, 1.62, 1.57, 1.44, 1.7, : arguments imply differing number of rows: 0, 736

global.R

#Import File From Computer
data <- read.csv("C:\\Users\\User\\Documents\\Project\\Shiny\\data.csv", header=TRUE)

The data can be replicated with the following commands:

Type <- c('A','A','A','B','B','B','C','C','C',)
Date <- as.Date(c('2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14'))
Run <- c('RUN1','RUN2','RUN3','RUN1','RUN2','RUN3','RUN1','RUN2','RUN3')
Var1 <- c(1,2,3,4,5,6,7,8,9)
Var2 <- c(2,4,6,8,10,12,14,16,18)
Var3 <- c(3,6,9,12,15,18,21,24,27)
Var4 <- c(4,8,12,16,20,24,28,32,36)
data <- data.frame(Type,Date,Run,Var1,Var2,Var3,Var4)

ui.R

library(googleVis)

shinyUI(fluidPage(
titlePanel("Visualization Tool"),
sidebarLayout(
headerPanel('Data Selection'),
 sidebarPanel(
selectInput('x', 'X Variable', names(data)),
selectInput('y', 'Y Variable', names(data)),
selectInput('z', 'Z Variable', names(data),
selected=names(data)[[5]]),

checkboxGroupInput('Type', 'Type', c(
  "A"="A",
  "B"="B",
  "C"="C")),
checkboxGroupInput('Run', 'Run', c(
  "RUN1"="RUN1",
  "RUN2"="RUN2",
  "RUN3"="RUN3"))

)),

mainPanel(htmlOutput(("chart"))
)
))

server.R

library(shiny)
library(googleVis)

shinyServer(function(input, output){
datasetInput <- total
output$chart <- renderGvis({
gvisBubbleChart(datasetInput, idvar=input$Name, xvar=input$x, yvar=input$y,
                color=input$Name, sizevar=input$z)
 })
})
Was it helpful?

Solution

I figured it out... In ui.R, I changed the names to a vector

xx<-c("Type"="Type", "Date"="Date", "Run"="Run","Var1"="Var1","Var2"="Var2","Var3"="Var3","Var4"="Var4")

ui.R becomes:

library(googleVis)

shinyUI(fluidPage(
titlePanel("Visualization Tool"),
sidebarLayout(
headerPanel('Data Selection'),
 sidebarPanel(
selectInput('x', 'X Variable', xx),
selectInput('y', 'Y Variable', xx),
selectInput('z', 'Z Variable', xx),


checkboxGroupInput('Type', 'Type', c(
  "A"="A",
  "B"="B",
  "C"="C")),
checkboxGroupInput('Run', 'Run', c(
  "RUN1"="RUN1",
  "RUN2"="RUN2",
  "RUN3"="RUN3"))

)),

mainPanel(htmlOutput(("chart"))
)
))

server.R becomes:

library(shiny)
library(googleVis)

shinyServer(function(input, output){
datasetInput <- reactive({data[data$Type %in% input$Type,]})
output$chart <- renderGvis({
gvisBubbleChart(datasetInput(), idvar="Type", xvar=input$x, yvar=input$y,
                color="Type", sizevar=input$z)
 })

})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top