diff --git a/app/server.R b/app/server.R index 7422eda..79f1de7 100644 --- a/app/server.R +++ b/app/server.R @@ -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 @@ -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 @@ -677,8 +679,7 @@ server = function(input, output, session) { list_both$code }) }) - - + } # server ends here diff --git a/plots/00_Plots-Bar.R b/plots/00_Plots-Bar.R index 633ef18..56a8cf2 100644 --- a/plots/00_Plots-Bar.R +++ b/plots/00_Plots-Bar.R @@ -29,7 +29,7 @@ bar_plot <- function(data=NULL, legendPos='right', title_x='', title_y='', - colourfill='#00FF0080', + colourfill='#2219CCCC', plotTitle='', facetRow, facetCol, @@ -37,11 +37,9 @@ bar_plot <- function(data=NULL, 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))) + @@ -66,7 +64,8 @@ bar_plot <- function(data=NULL, # p <- p + scale_fill_manual(values = colourfill) # } # - + + code <-HTML(paste0('
ggplot(data = ',df_name, ' , aes(x=', x, ', y=', y, ifelse(colorby=="None",")) + 
",paste0(',' ,'fill = ',colorby, ')) +
')), paste0('geom_bar(stat="identity" , position = ',shQuote(position)), ifelse(colorby=="None",paste0(', fill =',shQuote(colourfill), ') +
'), ') +
'), paste0(ifelse(Theme=="NULL" | is.null(Theme),'',paste0(' ',Theme,'+
'))), @@ -88,8 +87,10 @@ bar_plot <- function(data=NULL, ifelse(facetRow != 'None' & facetCol == 'None',paste0('+
facet_grid(',facetRow,' ~ .) '),'' ), ifelse(facetRow == 'None' & facetCol != 'None',paste0('+
facet_grid(. ~ ',facetCol,') ') ,''), ifelse(coorflip==TRUE, paste0('+
coord_flip()'),paste0('')), + ifelse(interactive == TRUE, paste0(' %>% ggplotly()'), paste0('')), '
')) + # # facet # if(facetRow != 'None' & facetCol != 'None'){ # p <- p + facet_grid(as.formula(paste0(facetRow, "~", facetCol))) @@ -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