Я создал раскрывающийся список лет с 2008 по 2018 год, используя блестящий пакет R. У меня есть график, который сравнивает количество моделей автомобилей марок автомобилей США и количество моделей автомобилей марок автомобилей в моей базе данных. Я создалГрафик с использованием графического пакета и базы данных подключен.Я хочу, чтобы в течение года проводилось сравнение моделей. Но когда я выбираю год из выпадающего списка, график не меняется. Никаких изменений не происходит для каждого выбора года. Код R указан ниже
library(shiny)
library(plotly)
library(data.table)
library(DBI)
library(RMySQL)
library(webshot)
dealerinventory1<-dbConnect(RMySQL::MySQL(), user='gbfb',
password='gfhgfhh!',
host='ffdhgfh',
dbname='gdfhgfhn')
param_modelyear=c(2008:2018)
for ( i in modelyr){
print(i)
}
modelyearquery=paste0(" (SELECT A.makename as AutonginMake,Case when B.makename is null Then A.makename
Else B.makename end As USMakename
,A.AutonginModelcount,Case when B.USModelcount is null Then 0
Else B.USModelcount end as USModelcount
FROM (select count(*) as AutonginModelcount,makename as makename from
(select distinct makename ,modelname from dealer_inventory.car_inventory_json_lookup where modelyear=",param_modelyear," order by makename) as C
group by makename) A Left JOIN (select count(*) as USModelcount,makename as makename from
(select distinct makename ,modelname from dealer_inventory.CarQuery where modelyear=",param_modelyear," order by makename) as D
group by makename) B ON A.makename=B.makename
ORDER BY A.makename)
UNION
(SELECT Case when A.makename is null Then B.makename
Else A.makename end As AutonginMake,B.makename as USMakename,Case when A.AutonginModelcount is null Then 0
Else A.AutonginModelcount end as AutonginModelcount,B.USModelcount
FROM (select count(*) as AutonginModelcount,makename as makename from
(select distinct makename ,modelname from dealer_inventory.car_inventory_json_lookup where modelyear=",param_modelyear," order by makename) as C
group by makename) A Right JOIN (select count(*) as USModelcount,makename as makename from
(select distinct makename ,modelname from dealer_inventory.CarQuery where modelyear=",param_modelyear," order by makename) as D
group by makename) B ON A.makename=B.makename
ORDER BY A.makename);")
makemodel1=dbGetQuery(dealerinventory1,modelyearquery)
plot5 <- plot_ly(makemodel1, x = ~AutonginMake, y = ~USModelcount, type = 'bar', name = 'USModelcount') %>%
add_trace(y = ~AutonginModelcount, name = 'AutonginModelcount') %>%
layout(
title="Yearwise comparison of Models of each Makes in Autongin and US market",
yaxis = list(title = 'modelcount'),
barmode = 'group')
k <- shinyUI(fluidPage(selectInput("my_dropdown","Choose Column",
param_modelyear),
plotlyOutput("plot")))
server5<- function(input,output){
output$plot=renderPlotly({
plot_ly(makemodel1, x = ~AutonginMake, y = ~USModelcount, type = 'bar', name = 'USModelcount') %>%
add_trace(y = ~AutonginModelcount, name = 'AutonginModelcount') %>%
layout(
title="Yearwise comparison of Models of each Makes in Autongin and US market",
yaxis = list(title = 'modelcount'),
barmode = 'group')
})
}
shinyApp(k,server5)