Hello I am just learning Shiny and Shinydashboard. I am having difficulty using the column names found from a data.frame loaded using the "fileInput" that was originally a .csv file. I would like to use these column names for the "selectInput" control choices? Eventually I want to plot different x-y data using the data.frame that was loaded, but I want to choose the specific x-y data variables since it will be different for each .csv data.frame I load.
Please see my ui.R and server.R files below that show what I was trying to do. I am also attaching an example .csv file that it the app will require to run. I would like to see the displayed table change it's columns depending on the choices that are made, and eventually write code that will plot one variable against another after I have selected them. I took example code from the following 2 examples, since it looks like I just need to "combine" these 2 examples:
Thanks in advance for any suggestions.
Kevin
ui.R
library(googleVis)
shinyUI(pageWithSidebar(
headerPanel(""),
sidebarPanel(
#create file upload control
fileInput('file1','Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
#create check box control to decide whether to include header
checkboxInput('header', 'Header', TRUE),
#use radio button control to decide the type of sepator in the file
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
#use radio button control to decide the type of quotes in the file
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
),
mainPanel(
htmlOutput('contents'),
uiOutput("choose_columns")
)
))
server.R
library(googleVis)
shinyServer(function(input, output) {
output$contents <- renderGvis({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
#load file that was specified by user and save into a uploaded data frame
upload.data=read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
# Check boxes
output$choose_columns <- renderUI({
colnames <- names(upload.data)
# Create the checkboxes and select them all by default
checkboxGroupInput("columns", "Choose columns",
choices = colnames,
selected = colnames)
})
## Output the uploaded data into a google table chart
gvisTable(head(upload.data))
})
})