尽管有输出,但Shiny拒绝绘制图表

蜥蜴人通用

我编写了Shiny应用程序,但由于某种原因,我在运行该应用程序时未显示任何图表。我以为可能是由于没有输出,但我仔细检查了一下,发现有一个。我的uiOutput工作正常,并且侧栏也仅由于未知原因而仅正确显示了该plotOutput。
代码如下所示:

library(shiny)
library(ggplot2)

#test<-read.csv("C:/Users/pawel/Desktop/AWD/PROJEKT/moj.csv")
#View(test)

ui <- fluidPage(
  titlePanel(""), sidebarLayout(
    sidebarPanel(
      helpText("Aplikacja pokazująca dane odnośnie ludzi, którzy ulegli poważnym wypadkom oraz informacje o ich rezultacie"),
      tags$hr(),
      fileInput("file"," Proszę podać ścieżkę do pliku CSV: "), 
      selectInput("att", "Proszę wybrać wykres", choices=c("Dane początkowe ","Ranking 10 najlepszych producentów "," Sprzedaż gier w danym regionie ","Global Sales ","NA Sales ","EU Sales ","Japan Sales"," Other Sales"),
                  selected="Dane początkowe", multiple=FALSE,selectize=TRUE)
    ),
  mainPanel(
    uiOutput("tb"),
    plotOutput("line")             
  ))
)

#server.R
server <- function(input,output){
  
  data <- reactive({
    
    file1 <- input$file
    if(is.null(file1)){return()} 
    
    read.csv(file=file1$datapath, sep=",", header=TRUE)})

    output$filedf <- renderTable({
    if(is.null(data())){return ()}
    input$file
  }) 

  output$sum <- renderTable({
    if(is.null(data())){return ()}
    summary(data())
  })

  output$table <- renderTable({
    if(is.null(data())){return ()}
    data()
  })
  
  
  output$line <- renderPlot({
    if (is.null(data())) { return() }
    
    
    else if(identical(input$att,"Dane początkowe")){
      print(ggplot(data(), aes(Genre, fill = as.factor(Genre) ) ) 
            + geom_bar() 
            + theme(text = element_text(size=20),axis.text.x = element_text(angle=90, hjust=1)) 
            + labs(title = "Ilość tytułów, na których jest przeprowadzana analiza z każdego z gatunków", x="Gatunek", y="Ilość tytułów")      
      )}
    
    
    else if(identical(input$att,"Ranking 10 najlepszych producentów")){
      a<- as.data.frame(table(table$Publisher))
      a <- a[order(a$Freq),] 
      z<-nrow(a)
      x<-nrow(a)-9
      b<- a[x:z,]
      print(pie(b$Freq, b$Var1, col = rainbow(length(b$Freq)), main="Ranking 10 producentów, którzy wydali najwięcej gier")
      )
    }
    
    
    else if(identical(input$att,"Sprzedaż gier w danym regionie")){
      Region <- c("NA", "EU", "JP", "OTHER", "GLOBAL")
      Sales <- c(sum(table$NA_Sales), sum(table$EU_Sales), sum(table$JP_Sales), sum(table$Other_Sales), sum(table$Global_Sales))
      newd<- data.frame(Region, Sales)
      print(ggplot(newd, aes(x=Region, y=Sales)) + 
              geom_bar(stat="identity", width=.5, fill='darkgoldenrod1') 
            + labs(title="Sprzedaż gier w zależności od regionu ")
            + theme(text = element_text(size=20))
      )
    }
    
    
    else if(identical(input$att,"Global Sales")){
      print(ggplot(data(), aes(table$Genre, table$Global_Sales)) 
            + geom_boxplot(colour="red") 
            + theme(text = element_text(size=15),axis.text.x = element_text(angle=90, hjust=1))  
            + facet_wrap(~Platform)
      )
    }
    
    
    
    else if(identical(input$att,"NA Sales")){
      print(ggplot(data(), aes(table$Genre, table$NA_Sales)) 
            + geom_boxplot(colour="red") 
            + theme(text = element_text(size=15),axis.text.x = element_text(angle=90, hjust=1))  
            + facet_wrap(~Platform)
      )
    }
    
    else if(identical(input$att,"EU Sales")){
      print(ggplot(data(), aes(table$Genre, table$EU_Sales)) 
            + geom_boxplot(colour="red") 
            +   scale_colour_continuous()
            + theme(text = element_text(size=15),axis.text.x = element_text(angle=90, hjust=1))  
            + facet_wrap(~Platform)
      )
    }
    
    else if(identical(input$att,"Japan Sales")){
      print(ggplot(data(), aes(table$Genre, table$JP_Sales)) 
            + geom_boxplot(colour="red") 
            + theme(text = element_text(size=15),axis.text.x = element_text(angle=90, hjust=1))  
            + facet_wrap(~Platform)
      )
    }
    
    else if(identical(input$att,"Other Sales")){
      print(ggplot(data(), aes(table$Genre, table$Other_Sales)) 
            + geom_boxplot(colour="red") 
            + theme(text = element_text(size=15),axis.text.x = element_text(angle=90, hjust=1))  
            + facet_wrap(~Platform)
      )
    }
  })
  output$tb <- renderUI({if(is.null(data())) h5()
    else
      tabsetPanel(tabPanel("Informacje o wczytanym pliku", tableOutput("filedf")),
                  tabPanel("Wczytane dane", tableOutput("table")),
                  tabPanel("Podsumowanie wczytanych danych", tableOutput("sum")))
  })
}

shinyApp(ui = ui, server = server)

我的应用看起来如何

如您所见,它正确加载了所有数据,但仍然拒绝加载图表。

蜥蜴人通用

没关系,我设法修复它,谢谢大家的帮助!问题在于selectInput中的随机空格键

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章