...Hello everyone,
I would like to have multiple plots from differents datasets, that are subsets of one data(core_table_long). I tried to get first plot with reactive values then observe function, but next plots seems not working. Next plots should be a factor variables with inputID="respondents_core". Any one to help please. See my codes below;
server <- function(input, output, session){
r_list <- reactiveValues()
observe({
dat <- core_table_long %>%
filter(Date == input$date)
r_list$filter_data <- dat
})
output$plot1 <- renderPlot({
r_list$filter_data%>%
select(core_dimension, Date, Score) %>%
group_by(.dots = c('Date', 'core_dimension')) %>%
summarise_all(funs(median(., na.rm = TRUE))) %>%
ggplot(aes( y=Score, x=as.factor(core_dimension), fill = Score)) +
geom_bar(stat = 'Identity', fill = "#9D9B4A", width = .6, show.legend = FALSE) +
geom_text(aes(label = paste(Score)), hjust = -0.3,
vjust = 0.1, size = 4.5, color = "black")+
theme_bw()+
coord_flip(clip = "off")+
theme_bw() +
expand_limits(y = c(0,5))+
theme(axis.title.x = element_blank(), axis.title.y = element_blank()) +
theme(panel.border = element_blank()) +
theme(panel.grid.minor.y=element_blank(),panel.grid.major.y=element_blank(),panel.grid.minor.x=element_blank(),panel.grid.major.x=element_blank(), axis.line.x.bottom = element_blank()) +
theme(axis.ticks = element_blank()) +
theme(axis.text.x = element_blank(),
axis.text.y = element_text( color = 'black'))
})
output$plot2 <- renderPlot({
r_list$filter_data %>%
select(core_dimension, Date, Score, input$respondents_core) %>%
group_by(.dots = c('Date', 'input$respondents_core', 'core_dimension')) %>%
summarise_all(funs(median(., na.rm = TRUE))) %>%
ggplot(aes_string( y="Score", x=as.factor(input$respondents_core), fill = "core_dimension")) +
geom_bar(stat = 'Identity', fill = "#9D9B4A", width = .6, show.legend = FALSE) +
geom_text(aes(label = paste(Score)), hjust = -0.3,
vjust = 0.1, size = 4.5, color = "black")+
theme_bw()+
coord_flip(clip = "off")+
theme_bw() +
expand_limits(y = c(0,5))+
theme(axis.title.x = element_blank(), axis.title.y = element_blank()) +
theme(panel.border = element_blank()) +
theme(panel.grid.minor.y=element_blank(),panel.grid.major.y=element_blank(),panel.grid.minor.x=element_blank(),panel.grid.major.x=element_blank(), axis.line.x.bottom = element_blank()) +
theme(axis.ticks = element_blank()) +
theme(axis.text.x = element_blank(),
axis.text.y = element_text(color = 'black'))
})
}
shinyApp(ui=ui, server=server)