shiny.gosling icon indicating copy to clipboard operation
shiny.gosling copied to clipboard

JS errors to r

Open federiva opened this issue 2 years ago • 2 comments

Closes #105

Changes description

  • Now we are catching errors in JS and sending them to a server function image

Steps to reproduce

Right now we are loading the library from a cdn. In order to test this PR before updating the file used in the CDN please do the following

  1. Download this and extract it to the inst/www folder
  2. Edit the goslingDependency function in components.R and replace it with the following in order to use a local version of it
goslingDependency <- function() {
  htmltools::htmlDependency(
    name = "gosling",
    version = "0.1.0",
    src = "www",
    package = "shiny.gosling",
    script = "gosling.js"
  )
}
  1. Run devtools::load_all()
  2. Run an example

federiva avatar Aug 25 '23 14:08 federiva

Codecov Report

Merging #123 (338a83a) into dev (1459956) will decrease coverage by 2.77%. Report is 84 commits behind head on dev. The diff coverage is 0.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff            @@
##              dev    #123      +/-   ##
=========================================
- Coverage   11.72%   8.96%   -2.77%     
=========================================
  Files          13      13              
  Lines         162     212      +50     
=========================================
  Hits           19      19              
- Misses        143     193      +50     
Files Changed Coverage Δ
R/composition.R 62.50% <ø> (ø)
R/data.R 0.00% <0.00%> (ø)
R/examples.R 0.00% <ø> (ø)
R/marks.R 0.00% <ø> (ø)
R/shiny.R 0.00% <ø> (ø)
R/styleProps.R 0.00% <ø> (ø)
R/utils.R 6.77% <0.00%> (-6.56%) :arrow_down:
R/visualChannels.R 0.00% <ø> (ø)

codecov-commenter avatar Aug 25 '23 17:08 codecov-commenter

Also adding an example app with shiny modules

library(shiny)
library(shiny.gosling)

areachart_ui <- function(id) {
  ns <- NS(id)
  fluidRow(
    column(
      width = 8,
      goslingOutput(ns("gosling_plot_test"))
    ),
    column(
      width = 4,
      fluidRow(
        column(
          2,
          actionButton(
            ns("download_png"),
            "PNG",
            icon = icon("cloud-arrow-down")
          )
        ),
        column(
          2,
          actionButton(
            ns("download_pdf"),
            "PDF",
            icon = icon("cloud-arrow-down")
          )
        )
      )
    )
  )
}


areachart_server <- function(id) {
  # Create data object ----
  view1_data <- track_data(
    url = "https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",
    type = "multivec",
    row = "sample",
    column = "position",
    value = "peak",
    categories = list("sample 1")
  )
  
  # Create visual channels ----
  view1_x <- visual_channel_x(
    field = "position", type = "genomic", axis = "bottom"
  )
  
  view1_y <- visual_channel_x(
    field = "peak", type = "quantitative", axis = "right"
  )
  
  # Create single track ----
  single_track <- add_single_track(
    width = 800,
    height = 180,
    data = view1_data,
    mark = "area",
    x = view1_x,
    y = view1_y,
    size = visual_channel_size(
      value = 2
    )
  )
  
  # Compose the track ----
  single_composed_view <- compose_view(
    tracks = single_track,
    layout = "linear"
  )
  
  # Arrange the view above ----
  single_composed_views <- arrange_views(
    title = "Basic Marks: Area",
    subtitle = "This is a simple Area Chart",
    views = single_composed_view
  )
  
  moduleServer(id, function(input, output, session) {
    observeEvent(input$download_png, {
      export_png(component_id = "sars_cov2")
    })
    
    observeEvent(input$download_pdf, {
      export_pdf(component_id = "sars_cov2")
    })
    
    observeEvent(input$zoom_out, {
      zoom_to_extent(
        component_id = "sars_cov2",
        view_id = "view2_track1"
      )
    })
    
    output$gosling_plot_test <- renderGosling({
      gosling(
        component_id = "sars_cov2",
        single_composed_views,
        clean_braces = TRUE
      )
    })
  })
}

barchart_ui <- function(id) {
  ns <- NS(id)
  fluidRow(
    column(
      width = 8,
      goslingOutput(ns("gosling_plot_test"))
    ),
    column(
      width = 4,
      fluidRow(
        column(
          2,
          actionButton(
            ns("download_png"),
            "PNG",
            icon = icon("cloud-arrow-down")
          )
        ),
        column(
          2,
          actionButton(
            ns("download_pdf"),
            "PDF",
            icon = icon("cloud-arrow-down")
          )
        )
      )
    )
  )
}

barchart_server <- function(id) {
  # Create data object ----
  view1_data <- track_data(
    url = "https://resgen.io/api/v1/tileset_info/?d=UvVPeLHuRDiYA3qwFlm7xQ",
    type = "multivec",
    row = "sample",
    column = "position",
    value = "peak",
    categories = list("sample 1"),
    binSize = 5
  )
  
  # Create visual channels ----
  view1_x <- visual_channel_x(
    field = "start", type = "genomic", axis = "bottom"
  )
  
  view1_xe <- visual_channel_x(
    field = "end", type = "genomic",
  )
  
  view1_y <- visual_channel_y(
    field = "peak", type = "quantitative", axis = "right"
  )
  
  # Create single track ----
  single_track <- add_single_track(
    width = 800,
    height = 180,
    data = view1_data,
    mark = "bar",
    x = view1_x,
    xe = view1_xe,
    y = view1_y,
    size = visual_channel_size(
      value = 5
    )
  )
  
  # Compose the track ----
  single_composed_view <- compose_view(
    tracks = single_track,
    layout = "linear"
  )
  
  # Arrange the view above ----
  single_composed_views <- arrange_views(
    title = "Basic Marks: bar",
    subtitle = "This is a simple bar chart.",
    views = single_composed_view
  )
  
  moduleServer(id, function(input, output, session) {
    
    observeEvent(input$download_png, {
      export_png(component_id = "sars_cov2")
    })
    
    observeEvent(input$download_pdf, {
      export_pdf(component_id = "sars_cov2")
    })
    
    observeEvent(input$zoom_out, {
      zoom_to_extent(
        component_id = "sars_cov2",
        view_id = "view2_track1"
      )
    })
    
    output$gosling_plot_test <- renderGosling({
      gosling(
        component_id = "sars_cov2",
        single_composed_views,
        clean_braces = TRUE
      )
    })
  })
}

ui <- navbarPage(
  title = "shiny.gosling",
  use_gosling(),
  tabPanel(
    "Area",
    fluidPage(
      width = 12,
      areachart_ui("areachart")
    )
  ),
  tabPanel(
    "Barchart",
    fluidPage(
      width = 12,
      barchart_ui("barchart")
    )
  )
)

server <- function(input, output, session) {
  areachart_server("areachart")
  barchart_server("barchart")
}



shinyApp(ui, server)

federiva avatar Aug 25 '23 19:08 federiva