library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File"),
selectInput("col", "Select a column", character(0))
),
mainPanel(
tableOutput("table"),
textOutput("selected")
)
)
)
server <- function(input, output, session) {
data <- reactive({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
read.csv(inFile$datapath)
})
observeEvent(data(), {
updateSelectInput(session, "col", choices = names(data()))
})
output$table <- renderTable({
req(data())
head(data())
})
output$selected <- renderText({
req(data())
paste0("You've selected the column named ", input$col,
". It's mean value is: ", mean(data()[[input$col]]))
})
}
shinyApp(ui, server)