Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boxes in Plots all have the same title #13

Open
cabaJr opened this issue Mar 5, 2023 · 0 comments
Open

Boxes in Plots all have the same title #13

cabaJr opened this issue Mar 5, 2023 · 0 comments

Comments

@cabaJr
Copy link
Owner

cabaJr commented Mar 5, 2023

When generating a new box via mod_plot_server and its relative nested module with RenderUI, all the boxes from consecutive plots (i.e. all the boxes containing the actograms generated) appear with the same title.

code in mod_plots.R

mod_plots_server <- function(id, env, acto_selected, title, module_id, count, pos, session){
  
  moduleServer(
    id,
    function(input, output, session){
    ns <- session$ns
      output[[pos]] <- renderUI({
        mod_box_plot_ui(NS(id, module_id), title)
      })
      mod_box_plot_server(module_id = module_id, env = env, acto_selected = acto_selected, count = count, title = title)
    

  })
}

code in inner module mod_box_plot.R

mod_box_plot_ui <- function(id, plot_title){
  ns <- NS(id)
  tagList(
    
 shinydashboardPlus::box(title= plot_title, 
                         id = "boxwplot", 
                         width = 12, 
                         solidHeader = TRUE, 
                         collapsible = TRUE, 
                         status = "primary",
                         enable_dropdown = TRUE,
                         dropdown_icon = "wrench",
                         fluidRow(
                            column(width = 12,
                                   shinycssloaders::withSpinner(plotOutput(ns("plot_hold")), id = "spin", type = 4, color = "#2E9AFE", size = 0.65)
                                   )
                            ),
                         fluidRow(
                            column(width = 2, 
                                   offset = 7,
                                   downloadButton(outputId = ns("download_1"), label = "Download plot")),
                            column(width = 2, 
                                   offset = 0,
                                   downloadButton(outputId = ns("download_2"), label = "Download data"))
                            )
 )
 
  )
}
    
#' box_plot Server Functions
#'
#' @noRd 
mod_box_plot_server <- function(module_id, env, acto_selected, count, title){
   moduleServer(module_id, function(input, output, session){
      ns <- session$ns
      Annotate <- env$env4$Annotate
      Custom_tables <- env$env3$Custom_tables
      ## get object containing the corresponding plot from table in Annotate
      plot_location <- eval(parse(text = unlist(acto_selected[count, 3]), n =1))
      plot_path <- unlist(acto_selected[count, 3])
      ## print the parsed plot  
      output$plot_hold <- renderPlot(plot_location)
      # Download function
      # download function to be incorporated in an external function that 
          # receives plot name and plot location
         filename_part <- unlist(acto_selected[count, 1])
         ## add option in the function to set resolution
         output$download_1 <- downloadHandler( #set an option to choose the quality of the output image
             #fix filename generator
             filename = function(){paste(title, "_", Sys.Date(), ".png", sep = "")},
             content = function(file){
               png(file, width = 1820, height = 787, units = "px")
               print(plot_location)
               dev.off()
             }
           )
         output$download_2 <- download_obj(title = acto_selected[count, 6],
                                           location = eval(parse(text = unlist(acto_selected[count, 5]), n =1)),
                                           format = "csv")
           
        
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant