2017-10-16 6 views
0

Dataerreur: Object « sortie » not found

obtenir erreur:

output object not found 

ne sais pas pourquoi cela se produit, je l'ai fait la même chose sur le tableau de bord passé ce moment aucune erreur. objet de sortie est spécifié, mais il ne peut pas détecter

Server.R

d <-read_excel("data/ds.xlsx",sheet = 1) 
output$plot1 <- renderPlotly({ 
data <- switch(input$var, 
      "Beginning Stocks (1000 MT)"= d$`Beginning Stocks (1000 MT)` 
      ,"Area Harvested (1000 HA)" = d$`Area Harvested (1000 HA)` 
      ,"Yield (MT/HA)" = d$`Yield (MT/HA)` 
      ,"Production (1000 MT)" = d$`Production (1000 MT)` 
      ,"MY Imports (1000 MT)" =d$`MY Imports (1000 MT)` 

     ) 
    data1 <- switch(input$var1, 
       "Beginning Stocks (1000 MT)"= d$`Beginning Stocks (1000 
       MT)` 
       ,"Area Harvested (1000 HA)" = d$`Area Harvested (1000 HA)` 
       ,"Yield (MT/HA)" = d$`Yield (MT/HA)` 
       ,"Production (1000 MT)" = d$`Production (1000 MT)` 
       ,"MY Imports (1000 MT)" =d$`MY Imports (1000 MT)` 
         ) 
     plot_ly(d, x =~d$`Attributes (Unit)`, y = ~data,type= "scatter",mode = 
     'markers+lines', marker = list(size = 10),name=input$var) %>% 
     add_trace(x = ~d$`Attributes (Unit)`, y = ~data1,type="scatter" 
     ,mode="markers+lines",name=input$var1) 
     }) 

UI.R

navbarPage("Barley Dashboard", 
     tabPanel("Balance sheet", 
       fluidPage(theme = shinytheme("united"), 
      mainPanel(fluidRow(column(8,selectInput("var",selected="select", 
      label = "Choose first variable",           
     choices = c("Beginning Stocks (1000 MT)","Area Harvested (1000 
     HA)","Yield (MT/HA)","Production (1000 MT)","MY Imports (1000 
     MT)") 
          ) 
          ), 
     column(8,selectInput("var1", selected = "select", 
     label = "Choose second variable",choices = c("Beginning Stocks 
     (1000 MT)", "Area Harvested (1000 HA)","Yield (MT/HA)","Production 
      (1000 MT)","MY Imports (1000 MT)") 
          ) 
          ) 
          ), 
      plotlyOutput("plot1") 
     )))) 

obtenir erreur: Error in output$plot1 <- renderPlotly({ : object 'output' not found

Je ne suis pas capable de corriger l'erreur

+1

Avez-vous 'server <- fonction (entrée, sortie, session) {' – akrun

+0

@akrun non j'ai créé des onglets séparés pour l'interface utilisateur et le serveur, donc pas inclus –

+0

Alors, comment puis-je résoudre ce problème? –

Répondre

0

J'ai reproduit votre exemple dans un seul fichier app.R dans un dossier nommé "app". Ne pas oublier de charger les paquets concernés avec library! En outre, ne pas rompre les lignes dans les choix selectInput car cela sera utilisé pour les noms de colonnes. Les choses que vous faites avec les switch() peuvent être traitées directement par Shiny en récupérant les noms de la colonne d'entrée de d dans plot_ly(). N'oubliez pas d'importer votre jeu de données (d) dans votre script.

library(shinythemes) 
library(plotly) 

ui <- navbarPage("Barley Dashboard", 
      tabPanel("Balance sheet", 
        fluidPage(theme = shinytheme("united"), 
           mainPanel(fluidRow( 
           column(8, 
             selectInput("var", 
                selected="select", 
                label = "Choose first variable",      
                choices = c("Beginning Stocks (1000 MT)", 
                   "Area Harvested (1000 HA)","Yield (MT/HA)", 
                   "Production (1000 MT)","MY Imports (1000 MT)")) 
          ), 
           column(8,selectInput("var1", selected = "select", 
                label = "Choose second variable", 
                choices = c("Beginning Stocks (1000 MT)", 
                   "Area Harvested (1000 HA)","Yield (MT/HA)", 
                   "Production (1000 MT)","MY Imports (1000 MT)"))) 
          ), 
           plotlyOutput("plot1") 
          )) 
        )) 

library("openxlsx") 
d <- read.xlsx("ds.xlsx", check.names = F) 
# Handle the changes of the colnames with dots instead of spaces due to read.xlsx() 
names(d) <- gsub(x = names(d), pattern = "\\.", replacement = " ") 

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

    output$plot1 <- renderPlotly({ 
    #browser() 
    plot_ly(d, x =~d$`Attributes (Unit)`, y = ~d[,input$var], 
      type= "scatter",mode = 'markers+lines', 
      marker = list(size = 10),name=input$var) %>% 
    add_trace(x = ~d$`Attributes (Unit)`, y = ~d[,input$var1],type="scatter", 
       mode="markers+lines", name=input$var1,yaxis="y2") 
}) 
} 

shinyApp(ui=ui, server = server) 

enter image description here

Bien que je ne pense pas que ce soit la sortie que vous attendiez de add_trace() dans votre code plot_ly.

+0

pouvez-vous m'aider en ajoutant la trace dans complot @Antoine Pissoort –