renkun-ken / formattable

Formattable Data Structures
Other
694 stars 78 forks source link

saveWidget not working? #48

Open happyshows opened 8 years ago

happyshows commented 8 years ago
[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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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

timelyportfolio commented 8 years ago

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

happyshows commented 8 years ago

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 commented 8 years ago
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 commented 8 years ago

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

happyshows commented 8 years ago

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 commented 8 years ago

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

happyshows commented 8 years ago

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

happyshows commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Is there anyway to skip the generation of test_files?

timelyportfolio commented 8 years ago

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 commented 8 years ago

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

mark-druffel commented 6 years ago

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