Skip to content

Instantly share code, notes, and snippets.

@stla
Created September 10, 2013 19:25
Show Gist options
  • Save stla/6514319 to your computer and use it in GitHub Desktop.
Save stla/6514319 to your computer and use it in GitHub Desktop.
How to use renderChart2() when the data file has not been uploaded yet ?
library(shiny)
library(rCharts)
library(data.table)
####
#### Server
####
shinyServer(function(input, output) {
##
## load data csv file
##
fileInput <- reactive( {
if (is.null(input$files)){ # User has not uploaded a file yet
return(NULL)
}
input$files
})
##
## output message : file loaded
##
output$loaded <- reactive({
if (is.null(input$files)){ # User has not uploaded a file yet
return("no file loaded yet")
}
""
})
##
## read data file
##
dataInput <- reactive({
if (is.null(input$files)){ # User has not uploaded a file yet
return(NULL) # WHAT COULD WE PUT HERE ???
}
inFile <- input$files
read.csv(inFile$datapath, header=T)
})
##
## output: print contents of loaded file
##
output$dat <- renderChart2({
dTable(dataInput())
})
})
library(shiny)
library(rCharts)
library(data.table)
####
#### UI
####
shinyUI(pageWithSidebar(
headerPanel("SAP import"),
##
## sidebar panel
##
sidebarPanel(
fileInput("files", "File data", multiple=FALSE)
),
##
## main panel
##
mainPanel(
tabsetPanel(
tabPanel("Data",
textOutput("loaded"),
br(),
chartOutput("dat", 'datatables')
)
),id="idtab"
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment