How to upload a file and name columns in Shiny in R?

purpose

To load a file into a Shiny application that reads data, name the variables (columns) and do some data analysis before presenting the graph output

Link Brilliant app

I use this app from the Shiny Gallery as a link: enter a description of the link here

What I tried:

I want to use the downloaded data on many outputs after performing various analyzes. So, instead of reading the file inside renderTableor renderPlot, I read it in a function server:

server <- function(input, output) {
     inFile <- reactive({input$file1})
     sdf <- reactive({read.csv(inFile()$datapath, header=F)})     

colnames(sdf()) <- c('Vehicle.ID', 'Time', 'Vehicle.class.no', 'Vehicle.type2', 
                         'Vehicle.Length', 'Lane', 'Preceding.Vehicle.ID', 'Spacing','Spacing2', 'State',
                         'svel.mps', 'deltaV.mps', 'sacc', 'lane.change')  }

Error

But when I run this application, I get:

brilliant :: runApp ('app-CC')

Listening on http://127.0.0.1:7484
Error in colnames(sdf()) <- c("Vehicle.ID", "Time", "Vehicle.class.no",  : 
  invalid (NULL) left side of assignment

Question

? render*. - , , , - render*?

+4
2

read.csv

server <- function(input, output) {
     inFile <- reactive({input$file1})
     sdf <- reactive({
         read.csv(inFile()$datapath, header=F, col.names = c('Vehicle.ID', 'Time', 'Vehicle.class.no', 'Vehicle.type2', 
            'Vehicle.Length', 'Lane', 'Preceding.Vehicle.ID', 'Spacing','Spacing2', 'State',
            'svel.mps', 'deltaV.mps', 'sacc', 'lane.change')  
         )
     }) 
}

, , ,

server <- function(input, output) {
     inFile <- reactive({input$file1})
     sdf <- reactive({
         dd<-read.csv(inFile()$datapath, header=F)
         colnames(dd) <- c('Vehicle.ID', 'Time', 'Vehicle.class.no', 'Vehicle.type2', 
            'Vehicle.Length', 'Lane', 'Preceding.Vehicle.ID', 'Spacing','Spacing2', 'State',
            'svel.mps', 'deltaV.mps', 'sacc', 'lane.change')  
         )
         dd
     }) 
}
+3

actionButton, . observeEvent, , , - "", , . , , , "" reactiveValue(), (, , , Shiny, , JS.)

0

Source: https://habr.com/ru/post/1598754/


All Articles