Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
vivian_shiny_intro_meetup_case_study
# this solution is contributed by Jay Grossman who attended that intro session! Good job, Jay!
# I asked everyone to creat a app which could upload csv data and build linear regression model
shinyServer(function(input, output) {
#output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects and uploads a
# file, it will be a data frame with 'name', 'size', 'type', and 'datapath'
# columns. The 'datapath' column will contain the local filenames where the
# data can be found.
# inFile <- input$file1
#if (is.null(inFile))
# return(NULL)
#csv <- read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
#summary(lm(speed~dist,data=csv))
# })
output$summary <- renderPrint({
# input$file1 will be NULL initially. After the user selects and uploads a
# file, it will be a data frame with 'name', 'size', 'type', and 'datapath'
# columns. The 'datapath' column will contain the local filenames where the
# data can be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
csv <- read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
summary(lm(speed~dist,data=csv))
})
output$view <- renderPlot({
# input$file1 will be NULL initially. After the user selects and uploads a
# file, it will be a data frame with 'name', 'size', 'type', and 'datapath'
# columns. The 'datapath' column will contain the local filenames where the
# data can be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
csv <- read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
plot(lm(speed~dist,data=csv))
})
})
# this solution is contributed by Jay Grossman who attended that intro session! Good job, Jay!
# I asked everyone to creat a app which could upload csv data and build linear regression model
shinyUI(pageWithSidebar(
headerPanel("CSV Viewer"),
sidebarPanel(
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',
c(Comma=',',
Semicolon=';',
Tab='\t'),
'Comma'),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'Double Quote')
),
# mainPanel(
# tableOutput('contents')
#)
mainPanel(
verbatimTextOutput("summary"),
plotOutput("view")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment