I want to create Shiny app where user will upload a csv file, upon uploading drop down box will populate with all the variables in dataset.
When user selects one of the variables from drop down box , corresponding histogram should be plotted in main panel.
Here is what I have done
ui.r File
library(shiny)
shinyUI(pageWithSidebar(
headerPanel( "Demand Forecast", "Flowserve"),
sidebarPanel(
fileInput('file1', 'Select csv file',accept=c('text/csv')
),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator', c(Comma=',',Tab='\t', Semicolon=';' )
),
tags$hr(),
selectInput("product", "Select: ","")
),
mainPanel(tableOutput('contents'),
plotOutput("hist")
)
))
server.r File
library(shiny)
library(ggplot2)
shinyServer(function(input,output,session){
dataUpload<-reactive({
inFile<-input$file1
print(inFile)
if(is.null(inFile))
return(NULL)
dt_frame = read.csv(inFile$datapath, header=input$header, sep=input$sep)
updateSelectInput(session, "product", choices = names(dt_frame))
})
output$hist <- renderPlot({
dataset<- dataUpload()
hist(dataset[,dataset$product])
})
})
But when I run this app it gives me an error object of type 'closure' is not subsettable
Please Help..
Thanks in advance
dt
is a function in base R (see?dt
), and when you calldt[, colm]
without the data framedt
existing in the scope, R will try to subset the functiondt
. So see if you can work out why your data framedt
is not within the scope of yourhist
call. - jbaumshist()
function numeric? - Keniajin