Last active
February 6, 2016 18:31
-
-
Save aagarw30/432b71179bbc525d2b52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(data.table) | |
# use the below options code if you wish to increase the file input limit, | |
# in this example file input limit is increased from 5MB to 9MB | |
options(shiny.maxRequestSize = 700*1024^2) | |
shinyServer(function(input,output){ | |
# This reactive function will take the inputs from UI.R and use them for read.table() to read the data from the file. It returns the dataset in the form of a dataframe. | |
# file$datapath -> gives the path of the file | |
data <- reactive({ | |
file1 <- input$file | |
if(is.null(file1)){return()} | |
fread(input=file1$datapath, sep="auto", header = input$header, stringsAsFactors = input$stringAsFactors) | |
}) | |
# this reactive output contains the summary of the dataset and display the summary in table format | |
output$filedf <- renderTable({ | |
if(is.null(data())){return ()} | |
input$file | |
}) | |
# this reactive output contains the summary of the dataset and display the summary in table format | |
output$sum <- renderTable({ | |
if(is.null(data())){return ()} | |
summary(data()) | |
}) | |
# This reactive output contains the dataset and display the dataset in table format | |
output$table <- renderTable({ | |
if(is.null(data())){return ()} | |
data() | |
}) | |
# the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset. | |
output$tb <- renderUI({ | |
if(is.null(data())) | |
h5("Powered by", tags$img(src='RStudio-Ball.png', heigth=200, width=200)) | |
else | |
tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum"))) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyUI(fluidPage( | |
titlePanel("File Input"), | |
sidebarLayout( | |
sidebarPanel( | |
fileInput("file","Upload the file"), # fileinput() function is used to get the file upload contorl option | |
helpText("Default max. file size is 5MB"), | |
tags$hr(), | |
h5(helpText("Select the read.table parameters below")), | |
checkboxInput(inputId = 'header', label = 'Header', value = FALSE), | |
checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE), | |
br(), | |
radioButtons(inputId = 'sep', label = 'Separator', choices = c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ',') | |
), | |
mainPanel( | |
uiOutput("tb") | |
# use below code if you want the tabset programming in the main panel. If so, then tabset will appear when the app loads for the first time. | |
# tabsetPanel(tabPanel("Summary", verbatimTextOutput("sum")), | |
# tabPanel("Data", tableOutput("table"))) | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment