Thanks for your suggestion. I checked that question before I asked my own but I couldn´t fix my problem. I define a vector var_name<-reactive(input$xcol) and then I used tableData[,c("var_name")] as the input in the hist function but with no success.
I´m building an app in which the user can upload his own file and make some analysis. I could manage to update the variable´s names in a selectInput each the user upload a different file. Now my issue is that I can´t pass the variable selected in the selectInput to build a histogram. How could I pass the variable selected as an input to a histogram? Here is my ui.r code. Once I execute my code the error I get in my app is "object of type 'closure' is not subsettable". Any advice please? Thanks
library(shiny)
ui<-fluidPage(
titlePanel(title = "My app"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Cargar archivo',
accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
),
checkboxInput('header', '¿Contiene Encabezado?', TRUE),
radioButtons('sep', 'Delimitador',
c(Comma=',',
"Punto y coma"=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(Ninguna='',
'Dobles'='"',
'Simples'="'"),
'"'),
radioButtons('resume', 'Summary',
c('Individual',
'Múltiple'), selected = "Múltiple",
inline = TRUE),
conditionalPanel("input.resume === 'Individual'",
selectInput('xcol', 'Variable X', ""),
sliderInput("bins","Seleccione el número de clases",min=5, max = 15, value = 6),
radioButtons("color","Seleccione un color", c("Amarillo","Azul","Rojo","Gris"), selected = "Azul", inline = TRUE)
)
),
mainPanel(h3("Muestra del archivo cargado:"),
tableOutput('contents'),
verbatimTextOutput("summary"),
plotOutput("histog")
)
)
)
server<-function(input, output, session) {
tableData <- reactive({
inFile <- input$file1
if (!is.null(inFile)){
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
}
else {
return(NULL)
}
})
observe({
updateSelectInput(
session,
"xcol",
choices=names(tableData()))
})
var_name<-reactive(input$xcol)
output$contents <- renderTable({
head(tableData())
})
output$summary <- renderPrint({
summary(tableData())
})
output$histog<-renderPlot({
hist(tableData[,c("var_name")],breaks= seq(0,10,l=input$bins+1), col(input$color))
})
}
shinyApp(ui = ui, server = server)