Skip to content

Commit

Permalink
interactive barplot code updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatel427 committed Sep 19, 2019
1 parent ee4635f commit c251e0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
9 changes: 5 additions & 4 deletions app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ server = function(input, output, session) {
facetRow = if(input$facetRow != 1){'None'}else{input$selectFacetRow},
facetCol = if(input$facetCol != 1){'None'}else{input$selectFacetCol},
position = input$position_input,
coorflip =input$coorflip_input
coorflip =input$coorflip_input,
interactive = input$interact
)$plot


Expand All @@ -333,7 +334,8 @@ server = function(input, output, session) {
facetRow = if(input$facetRow != 1){'None'}else{input$selectFacetRow},
facetCol = if(input$facetCol != 1){'None'}else{input$selectFacetCol},
position = input$position_input,
coorflip =input$coorflip_input
coorflip =input$coorflip_input,
interactive = input$interact
)$code


Expand Down Expand Up @@ -677,8 +679,7 @@ server = function(input, output, session) {
list_both$code
})
})




} # server ends here

26 changes: 10 additions & 16 deletions plots/00_Plots-Bar.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ bar_plot <- function(data=NULL,
legendPos='right',
title_x='',
title_y='',
colourfill='#00FF0080',
colourfill='#2219CCCC',
plotTitle='',
facetRow,
facetCol,
hideAxis,
axisAngle=90,
position='',
coorflip=FALSE,
interactive=FALSE) {
if(interactive==FALSE){



interactive) {


p <- ggplot(data, aes_string(x, y, fill =ifelse(colorby == 'None', shQuote("None"), colorby) )) +
geom_bar(stat="identity" , position = position) + #if(position=='') {} else { paste0(',', position = position)} ) +
eval(parse(text=as.character(Theme))) +
Expand All @@ -66,7 +64,8 @@ bar_plot <- function(data=NULL,
# p <- p + scale_fill_manual(values = colourfill)
# }
#



code <-HTML(paste0('<pre>ggplot(data = ',df_name, ' , aes(x=', x, ', y=', y, ifelse(colorby=="None",")) + <br> ",paste0(',' ,'fill = ',colorby, ')) + <br>')),
paste0('geom_bar(stat="identity" , position = ',shQuote(position)), ifelse(colorby=="None",paste0(', fill =',shQuote(colourfill), ') + <br>'), ') + <br>'),
paste0(ifelse(Theme=="NULL" | is.null(Theme),'',paste0('&ensp;',Theme,'+ <br>'))),
Expand All @@ -88,8 +87,10 @@ bar_plot <- function(data=NULL,
ifelse(facetRow != 'None' & facetCol == 'None',paste0('+ <br> facet_grid(',facetRow,' ~ .) '),'' ),
ifelse(facetRow == 'None' & facetCol != 'None',paste0('+ <br> facet_grid(. ~ ',facetCol,') ') ,''),
ifelse(coorflip==TRUE, paste0('+ <br> coord_flip()'),paste0('')),
ifelse(interactive == TRUE, paste0(' %>% ggplotly()'), paste0('')),
'</pre>'))


# # facet
# if(facetRow != 'None' & facetCol != 'None'){
# p <- p + facet_grid(as.formula(paste0(facetRow, "~", facetCol)))
Expand Down Expand Up @@ -131,19 +132,12 @@ bar_plot <- function(data=NULL,
# code <- paste0(code, '+ theme(axis.text.x = element_text(angle = ', axisAngle, ', hjust = 1))')
}
}



ls <- list()
ls[['plot']] <- p
ls[['code']] <- code
return(ls)

} else {


#data %>%


} # else ends for Theme


} #function ends here

0 comments on commit c251e0b

Please sign in to comment.