Добро пожаловать.selectInput and plot render
Я попытался показать графики, используя selectInput. Я установил selectInput с именем, названием, параметрами. В основном я добавляю шесть сюжетов ...
Как заставить его работать? Ошибка отсутствует, и все графики отображаются на одной странице.
.ui
library(shiny)
shinyUI(fluidPage(
headerPanel("Japan TeleCOM"),
includeCSS("styles.css"),
#
# Application title
titlePanel("Subscribers Market Share in Japan for Mobile Prepaid and Postpaid market and its' competition in 2000-2013"),
sidebarPanel
(
selectInput("statename", "Select plot", c("plotOne", "plotTwo", "plotThree", "plot4th", "plot5th", "plot6th"), selected = "PlotOne")
),
# Show a plot of the generated distrisbution
mainPanel(
plotOutput("plotOne"),
plotOutput("plotTwo"),
plotOutput("plotThree"),
plotOutput("plot4th"),
plotOutput("plot5th"),
plotOutput("plot6th")
)
))
.server (два участка, другой полугодовым код)
ibrary(shiny)
library(xlsx) # to read excel files
library(ggplot2) # to plot
library(scales) # to describe values on the plot 2,000,000 instead of 2000000
dataFromExcel <- read.xlsx(file="japan_telecom_dane.xlsx", sheetIndex=1,header=TRUE)
dataFromExcel2 <- read.xlsx(file="japan_telecom_dane_perc.xlsx", sheetIndex=1,header=TRUE)
###FIRST PLOT#####
shinyServer(function(input, output) {
df <- dataFromExcel
df2 <- dataFromExcel2
output$plotOne <- renderPlot({
df$Date <- as.Date(as.character(df$Date), format="%Y-%m-%d")
x <- df$Date # first column with Date
y <- df[ , 2:length(df)] # (all columns from df without the first one, the first column was x = Date)
plotGgplot <- ggplot() +
geom_line(data = df, aes(x = x, y = y$nttdocomo_prepaid, color=" nttdocomo_prepaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$nttdocomo_postpaid, color=" nttdocomo_postpaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$softbank_prepaid, color=" softbank_prepaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$softbank_postpaid, color=" softbank_postpaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$kddi_prepaid, color=" kddi_prepaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$kddi_postpaid, color=" kddi_postpaid "), linetype = 1, size = 1.6) +
ylab('Number of Subscribers') +
xlab('Year') +
scale_y_continuous (labels = comma, breaks = seq(from=0,to=190000000,by=5000000)) +
ggtitle("Subscribers in Japan for main privider and its' competition in 2000-2013") +
theme(plot.title=element_text(size=8, face="bold",
hjust = 0.5),
axis.title=element_text(size=8))
plotGgplot
})
#####Second PLOT######
output$plotTwo <- renderPlot({
df$Date <- as.Date(as.character(df$Date), format="%Y-%m-%d")
x <- df$Date # first column with Date
y <- df[ , 2:length(df)] # (all columns from df without the first one, the first column was x = Date)
plotGgplot <- ggplot() +
geom_line(data = df, aes(x = x, y = y$nttdocomo_postpaid, color=" nttdocomo_postpaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$softbank_postpaid, color=" softbank_postpaid "), linetype = 1, size = 1.6) +
geom_line(data = df, aes(x = x, y = y$kddi_postpaid, color=" kddi_postpaid "), linetype = 1, size = 1.6) +
ylab('Number of Subscribers') +
xlab('Year') +
scale_y_continuous (labels = comma, breaks = seq(from=0,to=190000000,by=20000)) +
ggtitle("Subscribers in Japan for main privider and its' competition in 2000-2013") +
theme(plot.title=element_text(size=8, face="bold",
hjust = 0.5),
axis.title=element_text(size=8))
plotGgplot
})
Спасибо человек !! Ты помог мне ! –