Je travaille sur l'élaboration d'une application pour faire (dans un premier temps) des graphiques simples avec Shiny.
Je rencontre un gros soucis de temps la réalisation de graphique ggplot avec 200k lignes étant assez longue (~20sec). Pour un jeu simmulé à deux colonnes. Mes données de bases étant plus grosses (200kl x 10 à 20cln) en fonction des tables).
Pour les motivés voici un ecm sur 200k ligne et deux colonnes :D
Code : Tout sélectionner
mod_graph2var_ui <- function(id){
ns <- NS(id)
tagList(
pageWithSidebar(
# title
headerPanel("Select Options"),
#input
sidebarPanel
(
selectInput(ns("dataset"), "Dataset" , "NONE", selected = "NONE"),
selectInput(ns("variable_x"), "Variable X", "NONE", selected = "NONE"),
selectInput(ns("variable_y"), "Variable Y", "NONE", selected = "NONE"),
selectInput(ns("group"), "Coloration", "NONE", selected = "NONE"),
selectInput(ns("plot_type"), "Plot Type:",
list(boxplot = "boxplot", points = "points",
lines = "lines_")
),
checkboxInput(ns("show.points"), "show points", FALSE),
actionButton(ns("updt_graph"), "Update graph")
),
# output
mainPanel(
h3(textOutput(ns("caption"))),
plotlyOutput(ns("plot_render"))
)
)
)
}
#' graph2var Server Functions
#'
#' @noRd
mod_graph2var_server <- function(id, my_tables){
moduleServer( id, function(input, output, session){
ns <- session$ns
shiny::observe({
#update variable and group based on dataset
updateSelectInput(session, "dataset",
label = "Vue:",
choices = names(my_tables),
selected = "environment")}, priority = 1)
shiny::observe({
#update variable and group based on dataset
if(!is.null(input$dataset)){
updateSelectInput(session, "variable_x", choices = colnames(my_tables[[input$dataset]]) )
updateSelectInput(session, "variable_y", choices = colnames(my_tables[[input$dataset]]) )
updateSelectInput(session, "group", choices = colnames( my_tables[[input$dataset]]) )
}#fin de if
})#Fin du observe
output$caption<- shiny::renderText({
switch(input$plot_type,
"boxplot" = "Boxplot",
"points" = "Distribution",
"lines_" = "Lignes"
) })
#plotting theme
theme_blank<- theme(
axis.line = element_line(colour = 'gray', size = .75),
panel.background = element_blank(),
plot.background = element_blank(),
legend.position = "none"
)
#plotting function using ggplot2
shiny::observeEvent(input$updt_graph, {
output$plot_render <- plotly::renderPlotly({
isolate(
if(input$dataset != "NONE" & input$variable_x != "NONE" &
input$variable_y != "NONE" & input$group != "NONE" ){
print("Debug On attaque le graph")
#dynamic plotting options
plot_fn<-switch(input$plot_type,
"boxplot" = ggplot2::geom_boxplot(),
"points" = ggplot2::geom_point(),
"lines_" = ggplot2::geom_line(),
)
x <- input$variable_x
y <- input$variable_y
grp <- input$group
plot_aes <- aes( x = .data[[x]],
y = .data[[y]],
color = .data[[grp]] )
p<-ggplot(my_tables[[input$dataset]]) + plot_aes + plot_fn
p<-p+labs(
fill = input$group,
x = input$variable_x,
y = input$variable_y
) +
theme_blank
if(input$show.points==TRUE) {
p<-p+ geom_point(color=plot_obj$group, alpha=0.5, position = 'jitter')
}
print(ggplotly(p))
}else{
p <- ggplot() + annotate("text", x = 5, y = 5,
label = "Pas de graphique maintenant") +
theme_blank
print(ggplotly(p))
print("Le graph est compilé")
}# fin du else
)#fin du isolate
})#Fin du renderPlot
})#Fin du observe updt_graph
}) #Close module server
}# Close definition of global function : mod_graph1var_server