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

saveWidget not working? #48

Open
happyshows opened this issue Feb 2, 2016 · 16 comments
Open

saveWidget not working? #48

happyshows opened this issue Feb 2, 2016 · 16 comments

Comments

@happyshows
Copy link

[df <- data.frame(
  id = 1:10,
  name = c("Bob", "Ashley", "James", "David", "Jenny", 
    "Hans", "Leo", "John", "Emily", "Lee"), 
  age = c(28, 27, 30, 28, 29, 29, 27, 27, 31, 30),
  grade = c("C", "A", "A", "C", "B", "B", "B", "A", "C", "C"),
  test1_score = c(8.9, 9.5, 9.6, 8.9, 9.1, 9.3, 9.3, 9.9, 8.5, 8.6),
  test2_score = c(9.1, 9.1, 9.2, 9.1, 8.9, 8.5, 9.2, 9.3, 9.1, 8.8),
  final_score = c(9, 9.3, 9.4, 9, 9, 8.9, 9.25, 9.6, 8.8, 8.7),
  registered = c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE),
  stringsAsFactors = FALSE)

test <- formattable(df, list(
  age = color_tile("white", "orange"),
  grade = formatter("span",
    style = x ~ ifelse(x == "A", style(color = "green", font.weight = "bold"), NA)),
  test1_score = color_bar("pink", 0.2),
  test2_score = color_bar("pink", 0.2),
  final_score = formatter("span",
    style = x ~ style(color = ifelse(rank(-x) <= 3, "green", "gray")),
    x ~ sprintf("%.2f (rank: %02d)", x, rank(-x))),
  registered = formatter("span", 
    style = x ~ style(color = ifelse(x, "green", "red")),
    x ~ icontext(ifelse(x, "ok", "remove"), ifelse(x, "Yes", "No")))
))

saveWidget(tst,'test.html')

Error in system.file(config, package = package) : 
  'package' must be of length 1](url)

@timelyportfolio
Copy link
Collaborator

For this to work, we'll need to explictly convert using as.htmlwidget first.

df <- data.frame(
  id = 1:10,
  name = c("Bob", "Ashley", "James", "David", "Jenny", 
           "Hans", "Leo", "John", "Emily", "Lee"), 
  age = c(28, 27, 30, 28, 29, 29, 27, 27, 31, 30),
  grade = c("C", "A", "A", "C", "B", "B", "B", "A", "C", "C"),
  test1_score = c(8.9, 9.5, 9.6, 8.9, 9.1, 9.3, 9.3, 9.9, 8.5, 8.6),
  test2_score = c(9.1, 9.1, 9.2, 9.1, 8.9, 8.5, 9.2, 9.3, 9.1, 8.8),
  final_score = c(9, 9.3, 9.4, 9, 9, 8.9, 9.25, 9.6, 8.8, 8.7),
  registered = c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE),
  stringsAsFactors = FALSE)

 test <- formattable(df, list(
   age = color_tile("white", "orange"),
   grade = formatter("span",
                     style = x ~ ifelse(x == "A", style(color = "green", font.weight = "bold"), NA)),
   test1_score = color_bar("pink", 0.2),
   test2_score = color_bar("pink", 0.2),
   final_score = formatter("span",
                           style = x ~ style(color = ifelse(rank(-x) <= 3, "green", "gray")),
                           x ~ sprintf("%.2f (rank: %02d)", x, rank(-x))),
   registered = formatter("span", 
                          style = x ~ style(color = ifelse(x, "green", "red")),
                          x ~ icontext(ifelse(x, "ok", "remove"), ifelse(x, "Yes", "No")))
 ))

htmlwidgets::saveWidget(as.htmlwidget(test),'test.html')

@happyshows
Copy link
Author

@timelyportfolio do you know what's this warning about?

pandoc.exe: Could not determine mime type fortest_files/bootstrap-3.3.5/css../fonts/glyphicons-halflings-regular.woff2'
Error: pandoc document conversion failed with error 1
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" F:\Stash\Apps\WSP\test.html --from markdown_strict --output F:\Stash\Apps\WSP\test.html --self-contained --template C:\Users\xle\AppData\Local\Temp\RtmpSUWrjr\filebb8267d55b1.html' had status 1 `

@timelyportfolio
Copy link
Collaborator

pandoc doesn't like woff2. I thought we had fixed this. Let me look and fix.

@timelyportfolio
Copy link
Collaborator

I believe this should now be fixed with 9637a33. Could you try it out?

@happyshows
Copy link
Author

I reinstalled using devtools::install_github("renkun-ken/formattable") is this the right way to patch a commit?

I'm still seeing the same error.

@happyshows
Copy link
Author

Downloading github repo renkun-ken/formattable@master
Installing formattable
"C:/Rhome/bin/x64/R" --vanilla CMD INSTALL  \
  "C:/Users/xle/AppData/Local/Temp/RtmpcZeXor/devtools23644d816028/renkun-ken-formattable-9637a33"  \
  --library="F:/RLib" --install-tests 

I think the commit is incorporated

@timelyportfolio
Copy link
Collaborator

What you did sounds right. Let me dig a little deeper. Are you getting this with saveWidget or with rmarkdown?

@happyshows
Copy link
Author

saveWidget, I was trying to use this in shiny to create a downloadable html for formattable. But I got the error even without using shiny.

@timelyportfolio
Copy link
Collaborator

is there a directory like test_files that still exists? I wonder if there is something stuck in cache.

@happyshows
Copy link
Author

I removed test_files and restarted R session, still the same :(

@happyshows
Copy link
Author

update: I have upgraded htmlwidgets to 0.5.2 and it's running without error now. However, it's running forever. But the generated test.html looks fine.

@timelyportfolio
Copy link
Collaborator

ok, great. I'm not sure what takes it so long. I am guessing all the bootstrap files. Glad it worked. That was going to be my next suggestion :)

@happyshows
Copy link
Author

Is there anyway to skip the generation of test_files?

@timelyportfolio
Copy link
Collaborator

not that I am aware of, but they should only be temporary and disappear after save. Is this not the way it works on your machine?

@happyshows
Copy link
Author

since it's running forever I had to kill the process which might skip the folder deletion code...

@mark-druffel
Copy link

I hit this issue as well trying to save a leaflet map... Anyone figure out a work around?

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

3 participants