2016-06-26 15 views
0

Ich habe angefangen, das Shiny-Paket zu verwenden, und ich habe Probleme mit der reaktiven Funktion. Link zu CSV-Datei - here Die reaktive Funktion wird in dem folgenden Code nicht funktioniert:glänzend R reaktive Funktion funktioniert nicht

library(shiny) 
    library(ggplot2) 
    library(jpeg) 
    library(grid) 
    library(DT) 

    ui<-shinyUI(fluidPage 
     (

     titlePanel("Rapid Interpretation of Eye Movements"), 
     tags$style("body {background-color: #ffffcc;}"), 
     fileInput('file1', 'Choose CSV File', 
        accept=c('text/csv', 
          'text/comma-separated-values,text/plain', 
          '.csv')), 
     tags$hr(), 
     fluidRow(
      column(width = 10, class = "well", 
       h4("Left plot controls right plot"), 
       fluidRow(
        column(width = 10,plotOutput("plot", height = 500, brush = brushOpts(id = "plot_brush", resetOnNew = TRUE))) 
       ))) 
     )) 

    server<- shinyServer(function(input,output,session){ 

    filedata <- reactive({ 
     infile <- input$file1 
     if (is.null(infile)) { 
     # User has not uploaded a file yet 
     return(NULL) 
     } 
     read.csv(infile$datapath) 
    }) 

    output$plot <-renderPlot({ 

     bg <- rasterGrob(readJPEG(
     paste0("C:/Users/tyaacov/Downloads/shinyProject/pics/1.jpg")), interpolate=TRUE) 

     fixationdata <- filedata() 

     df <- data.frame(fixationdata$HorzPos, 
         fixationdata$VertPos, 
         d = densCols(fixationdata$HorzPos, 
            fixationdata$VertPos, 
            colramp = colorRampPalette(rev(rainbow(10, end = 4/6))))) 



     ggplot(df) + annotation_custom(bg, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + 
     geom_point(aes(fixationdata$HorzPos, 
         fixationdata$VertPos, col = d), size = 1) + 
     scale_color_identity() + theme_bw() + scale_x_continuous(name="",limits = c(0, 920)) + theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) + scale_y_continuous(name="",limits = c(0, 255)) 
    }) 

    }) 

    shinyApp(ui=ui,server = server) 

ich Fehler über fixationdata bin Empfang nicht gefunden werden. Wenn ich die Dinge getrennt überprüfe, kann ich nur vermuten, dass die Quelle für dieses Problem die reaktive Funktion ist. Weiß jemand wo ich falsch lag?

+0

Willkommen bei StackOverflow. Gibt es eine UI-Datei, mit der ich versuchen könnte, sie auszuführen? –

+0

yeah .. den UI-Code zur Frage hinzugefügt .. Thaks .. –

+0

Großartig, das hilft, danke. Erhalten Sie auch den Fehler über ', width = '8%' ist eine ungültige Option? Gibt es noch andere Pakete, die du geladen hast? Ich glaube du hast 'raster',' jpeg' und 'grid' geladen, stimmt das? Kannst du die Datei 'C:/Users/tyaacov/Downloads/shinyProject/pics/1.jpg' anhängen? –

Antwort

0
library(shiny) 
library(ggplot2) 
library(jpeg) 
library(grid) 
library(DT) 

ui<-shinyUI(fluidPage 
      (

      titlePanel("Rapid Interpretation of Eye Movements"), 
      tags$style("body {background-color: #ffffcc;}"), 
      fileInput('file1', 'Choose CSV File', 
         accept=c('text/csv', 
           'text/comma-separated-values,text/plain', 
           '.csv')), 
      tags$hr(), 
      fluidRow(
       column(width = 10, class = "well", 
        h4("Left plot controls right plot"), 
        fluidRow(
         column(width = 10,plotOutput("plot", height = 500, brush = brushOpts(id = "plot_brush", resetOnNew = TRUE))) 
        ))) 
      )) 

server<- shinyServer(function(input,output,session){ 

    filedata <- reactive({ 
    infile <- input$file1 
    if (is.null(infile)) { 
     # User has not uploaded a file yet 
     return(NULL) 
    } 
    read.csv(infile$datapath) 
    }) 


    output$plot <-renderPlot({ 

    if (is.null(input$file1)) return() 
    #if (input$action==0) return() 
    #isolate({ 

    library(ggplot2) 

    fixationdata <- filedata() 

    df <- data.frame(fixationdata$HorzPos, 
        fixationdata$VertPos, 
        d = densCols(fixationdata$HorzPos, 
            fixationdata$VertPos, 
            colramp = colorRampPalette(rev(rainbow(10, end = 4/6))))) 
    ggplot(df) + 
     geom_point(aes(fixationdata$HorzPos, 
        fixationdata$VertPos, col = d), size = 1) + 
     scale_color_identity() + theme_bw() + scale_x_continuous(name="",limits = c(0, 920)) + theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) + scale_y_continuous(name="",limits = c(0, 255)) 
    #}) 

    }) 

}) 

shinyApp(ui=ui,server = server) 
+0

danke für Ihre Antwort. es ist immer noch der Fehler angezeigt - Fehler in eval: Objekt 'Fixationsdaten' nicht gefunden –

+0

Ich habe diesen Fehler nicht gesehen, haben Sie versucht, Update R und die Bibliotheken? – DemetriusRPaula