I wrote Shiny app but for some reason it shows no charts when I run it. I thought it might be due to no Output, but I double checked it and there is one. My uiOutput works perfectly fine and sidebar is also showing properly only this plotOutput is broken for an unknown reason.
Here is how the code looks like:
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)