When I try to execute the variance test in the R shiny app, it throws the error: undefined columns selected. Please take a look at the code and rectify it.
UI
#install.packages("shiny")
library(shiny)
shinyUI(fluidPage(
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
selectInput("type","Select the input type:",c("File"="file","Dataset"="ds","URL"="url")),
conditionalPanel(condition="input.type==\"file\"",
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"')),
conditionalPanel(condition="input.type==\"ds\"",
selectInput("ds","Select a Dataset",
choices=ls(package:datasets))),
conditionalPanel(condition="input.type==\"url\"",
textInput("url1","Enter the url here",
"http://users.stat.ufl.edu/~winner/data/cardiacoutput_measure.csv")),
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
selectInput("col1","Select the column",choices=NULL),
selectInput("type2","Select the input type:",c("File"="file3","Dataset"="ds1","URL"="url2")),
conditionalPanel(condition="input.type2==\"file3\"",
fileInput("file4", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"')),
conditionalPanel(condition="input.type2==\"ds1\"",
selectInput("ds2","Select a Dataset",
choices=ls(package:datasets))),
conditionalPanel(condition="input.type2==\"url2\"",
textInput("url3","Enter the url here",
"http://users.stat.ufl.edu/~winner/data/cardiacoutput_measure.csv")),
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
selectInput("col2","Select the column",choices=NULL),
selectInput("conmodel", "Select Model",
choices = c("Normal" = "normal",
"Exponential" = "exponential",
"Uniform" = "uniform"),
selected = "exponential"
),
conditionalPanel(
condition = "input.conmodel == 'uniform'",
numericInput("a", "parameter a in Normal" , value = -2),
numericInput("b", "parameter b in Normal" , value = 0.8)
),
conditionalPanel(
condition = "input.conmodel == 'normal'",
numericInput("mu", "parameter mu in Normal" , value = 0),
numericInput("sigma", "parameter sigma in Normal" , value = 1)
),
sliderInput("s", "number of simulated data" ,min=1, max=1000, value = 10),
selectInput("ttest","Select the test:",c("Variance Test"="vart",
"1 sample test"="ost",
"2 sample test"="tst",
"paired t test"="ptt"),selected=""),
conditionalPanel(condition="input.ttest=='ost'",
numericInput("c","Please enter the mean value",value=0)))
#conditionalPanel((condition="input.ttest=='tst'",
, mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Summary_1", verbatimTextOutput("summary1")),
tabPanel("Summary_2", verbatimTextOutput("summary2")),
tabPanel("Dataset_1", tableOutput("table1")),
tabPanel("Dataset_2", tableOutput("table2")),
tabPanel("Plot",plotOutput("myhist")),
tabPanel("Prob",tableOutput('prob')),
tabPanel("Variance Test",verbatimTextOutput('var')))
))))
server
library(BatchGetSymbols)
library(shiny)
server <- function(input, output,session) {
x <- reactive({
a<- switch(input$type,
file=
if(is.null(input$file1)) return(NULL) else
read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote),
ds=get(input$ds, "package:datasets"),
url= if(is.null(input$url1)) return(NULL) else
read.csv(url(input$url1))
)
if(input$disp == "head") {
return(head(a))
}
else {
return(a)
}
})
y <- reactive({
b<- switch(input$type2,
file3=
if(is.null(input$file4)) return(NULL) else
read.csv(input$file4$datapath,
header = input$header,
sep = input$sep,
quote = input$quote),
ds1=get(input$ds2, "package:datasets"),
url2= if(is.null(input$url3)) return(NULL) else
read.csv(url(input$url3))
)
if(input$disp == "head") {
return(head(b))
}
else {
return(b)
}