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

Saving highcharter objects to a path #101

Open
abresler opened this issue Oct 26, 2020 · 1 comment
Open

Saving highcharter objects to a path #101

abresler opened this issue Oct 26, 2020 · 1 comment

Comments

@abresler
Copy link

Ryan,

Appears like there are issue creating exportable trelliscopes with highcharter objects.

It works perfectly fine when you aren't exporting the trelliscope.

Here is a quick repro example:

library(trelliscopejs)
library(highcharter)
library(tidyverse)

tbl_mpg <- 
  mpg %>%
  nest(data = !one_of(c("manufacturer", "class"))) %>%
  mutate(cogs = map_cog(
    data,
    ~ tibble(
      mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"),
      mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"),
      most_common_drv = cog(tail(names(table(
        .$drv
      )), 1), desc = "Most common drive type")
    )
  ))

df <- tbl_mpg %>%
  mutate(panel = map_plot(data, function(x) {
    
    hchart(x, type = "scatter", hcaes(x = "cty", y = "hwy", group = "drv"))
  }))



viz_no_path <- df %>%
  trelliscope(
    name = "city_vs_highway_mpg",
    nrow = 1,
    ncol = 2,
    jsonp = T
  )

## Works but can't export
viz_no_path


viz_path_contained <- df %>%
  trelliscope(
    name = "city_vs_highway_mpg",
    nrow = 1,
    ncol = 2,
    path = "Desktop/test/hchart/contained",
    jsonp = T,
    self_contained = T
  )

## Opens but doesn't work
viz_path_contained 


viz_path_not_contained <- df %>%
  trelliscope(
    name = "city_vs_highway_mpg",
    nrow = 1,
    ncol = 2,
    path = "Desktop/test/hchart/uncontained",
    self_contained = F
  )

### Doesn't work
viz_path_not_contained
@abresler
Copy link
Author

Been trying to trouble shoot this a bit more.

It looks like even without explicitly setting the path when you search for it in the tmp folders and navigate to the index.html file the results are the same as the raw export mechanism.

However when you use use the path set to the index.html and launch the browseURL it works perfectly by setting up a localhost {same way it works without defining the path in the function where it the output renders but not in an exportable format.

library(trelliscopejs)
library(highcharter)
library(tidyverse)

tbl_mpg <-
  mpg %>%
  nest(data = !one_of(c("manufacturer", "class"))) %>%
  mutate(cogs = map_cog(
    data,
    ~ tibble(
      mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"),
      mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"),
      most_common_drv = cog(tail(names(table(
        .$drv
      )), 1), desc = "Most common drive type")
    )
  ))

df <- tbl_mpg %>%
  mutate(panel = map_plot(data, function(x) {

    hchart(x, type = "scatter", hcaes(x = "cty", y = "hwy", group = "drv"))
  }))



viz_no_path <- df %>%
  trelliscope(
    name = "city_vs_highway_mpg",
    nrow = 1,
    ncol = 2,
    jsonp = T
  )


viz_no_path  ## works in viewer


temp_path <- attr(viz_no_path, "trelliscope_pars")$www_dir

browseURL(temp_path) ## opens static trelliscope index.html file and doesn't work
file.path(path$www_dir, "index.html") %>% browseURL() ## does work!

Any idea if there is a way to export the localhost rendered version that does work?
Screen Shot 2020-12-21 at 9 52 22 AM
Screen Shot 2020-12-21 at 9 52 13 AM

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