the data points on the graph are not plotted, even though the header of the csv file can be shown, i think somewhere in my code its not able to read the data

Below is a code in which the user uploads a csv file, the code then goes on to plot a fft plot, but as you will see when clicked on the fft button it does not plot the data points on the graph, if anyone could help me, i would be really grateful.

i will upload the image of the app,which after clicking on the FFTPLOT action button looks like this
find the screenshot PFA

Also the csv input file
apparently i cant upload it :confused:

    library(ggplot2)

ui <- fluidPage(
  titlePanel("Apollo Tyres CLC "),
  sidebarLayout(
    
    sidebarPanel(
      
      fileInput("file1", "Choose CSV File",
                multiple = FALSE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv")),
      tags$hr(),
     
      checkboxInput("header", "Header", TRUE),
      tags$hr(),
      actionButton("rawdata","RawData_Plot"),
      br(),
      actionButton("fftdata","FFTPlot"),
      br(),
      actionButton("filter","FilterPlot"),
      br(),
      tags$hr(), 
      actionButton("clc","ContactLength"),
      br(),
      actionButton("rpm","RPM"),
      br(),
      actionButton("speed","EstimatedSpeed"),
      br(),
      tags$hr(),
      
      # Input: Select number of rows to display ----
      radioButtons("disp", "Display",
                   choices = c(Head = "head",
                               All = "all"),
                   selected = "head")
      
    ),
    
    # Main panel for displaying outputs ----
    mainPanel(
      
      # Output: Data file ----
      tableOutput("contents"),
      plotOutput("fftplot")
    )
    
  )
)

# Define server logic to read selected file ----
server <- function(input, output) {
 
  output$contents <- renderTable({
    
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, head of that data file by default,
    # or all rows if selected, will be shown.
    
    req(input$file1)
    
    # when reading semicolon separated files,
    # having a comma separator causes `read.csv` to error
    tryCatch(
      {
        df <- read.csv(input$file1$datapath,
                       header = TRUE)
      },
      error = function(e) {
        # return a safeError if a parsing error occurs
        stop(safeError(e))
      }
    )
  
    if(input$disp == "head") {
      return(head(df))
    }
    else {
      return(df)
    }
   
  })
 
  @@@@@@@@@@#######So the problem is in this code@@@@@2
  fftplot<- eventReactive(input$fftdata, {
    infile <- input$file1
    data <- read.csv(infile$datapath)
    data$X.axis.in.g = data$X.axis.in.g - mean(data$X.axis.in.g) ##DC offset removal##
    fftx = fft(data$X.axis.in.g) ##takes FFT##
    magx = Mod(fftx[1:(length(fftx)/2)]) ##magnitude of FFT##
    frequency = seq(0,100,length.out=length(magx)) ##frequency Range##
    fftdf = data.frame(magx,frequency) ##making a data frame of freq and mag##
    aabc = ggplot(fftdf,aes(x=frequency,y=magx,color=frequency)) 
    aabc+ geom_line()+coord_cartesian(ylim=c(0,3000)) +
      geom_smooth(method="lm")
    }) 
  
  output$fftplot <- renderPlot({fftplot()})
  @@@@@@@@@@##########@@@@@@@@@
}

# Create Shiny app ----
shinyApp(ui, server)``````


the warning message i am getting is 
Warning: Removed 5941 rows containing non-finite values (stat_smooth).
Warning: Removed 5941 rows containing missing values (geom_path).

There seems to be something with your data transformation where NA are introduced. ggplot remove those NAs before plotting. This could explain why you can"t see any points if all are NAs.

Did you test all this workflow outside of a shinyapp ? I would do it: Load the file, do the transformation, see how it goes and try to plot.

Without a data sample to help, and better a reprex, it is not easy to help you. If you can, please provide one. Thank you.

2 Likes

Thank you so much for replying so fast
yes, one sec, how should i send a csv file?
if you have an email i could forward you one

this link might work
http://www.sharecsv.com/s/b0ad3cbdc183d414d819971dba26dcb1/3axis.csv

yes this link is working. I can't test right now your code.
Please try your workflow outside of the shinyapps to see if it works, and if not provide a reprex without shiny, to isolate the issue. Thanks.

for the reprex issue, all i know at this point is what i have uploaded the code is all that there is, and i am uploading what the graph should look like outside shiny app,

the code i used for it was
data is the name of the dataframe

data <- read.csv ("3axis.csv")
data$X.axis.in.g = data$X.axis.in.g - mean(data$X.axis.in.g) ##DC offset removal##
    fftx = fft(data$X.axis.in.g) ##takes FFT##
    magx = Mod(fftx[1:(length(fftx)/2)]) ##magnitude of FFT##
    frequency = seq(0,100,length.out=length(magx)) ##frequency Range##
    fftdf = data.frame(magx,frequency) ##making a data frame of freq and mag##
    aabc = ggplot(fftdf,aes(x=frequency,y=magx,color=frequency))
    aabc+ geom_path()+coord_cartesian(ylim=c(0,3000))+
    geom_smooth(method = "lm")

i got it working sir. i forgot to add header = FALSE in my server code , in the fft code.

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: