-2

I am trying to create a html widget with flexdashboard elements in an object of class "shiny tag list". Expected output : An html file saved in my local drive. Actual output

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

Here is a minimized version of the code:

library(flexdashboard)
library(htmlwidgets)
library(htmltools)

myflex1<- gauge(1.5, min = 0, max = 5, symbol = '', gaugeSectors(success = c(0, 2),warning = c(2,3.5 ),danger = c(3.5, 5)))

myflex<-   browsable(tagList
                     (list(tags$div(
                             style = 'position: absolute;
                             left: 100px;top: 350px;display:block',
                             myflex1
                           ))))

htmlwidgets::saveWidget(myflex, "myflex.html")
user2554330
  • 37,248
  • 4
  • 43
  • 90
  • 1
    You'll need to post a minimal reproducible example if you want any help with this. – user2554330 Jan 30 '19 at 16:30
  • I will add the code snippet here. Thank you. – Dominic Xavier Jan 30 '19 at 16:54
  • That's not a reproducible example, and probably not minimal. You need to post something that is self-contained and generates the problem you are seeing. With that snippet, I get an error that the `browsable` function is not known. I can guess you mean the one in `htmltools`, but then I get an error about a missing `fileSize`, because I don't have a file satisfying `file.path("***.jpg")`. – user2554330 Jan 30 '19 at 20:17
  • Hello Sir, I have added the whole portion of the code with the required amends. Basically, i am trying to create a dashboard using flexdashboard gauges and creating a shiny tag list to create a html file. While the object created so is browsable on R, I am unable to save it using htmlwidget. Thank you – Dominic Xavier Jan 30 '19 at 22:06
  • You need to reduce your example to a *minimal* example that produces the problem. I'm not going to do your debugging for you. – user2554330 Jan 31 '19 at 00:38
  • Hello, My apologies. I have edited the code to the minimal example format and saved it again. Could you please help with the error? Thank you. – Dominic Xavier Jan 31 '19 at 17:05
  • `gauge` up there is missing its first argument. – Ramiro Magno Jan 31 '19 at 17:17
  • Hey Dominic, I think it'd be a good idea to peruse this bad boy before asking a question. Pasting *just* code is almostworst thing you could do! https://stackoverflow.com/help/mcve – Jared Wilber Jan 31 '19 at 17:27
  • The edits I had saved did not populate accurately. I have re-edited my code. Thank you. – Dominic Xavier Jan 31 '19 at 17:51

1 Answers1

0

The problem is that you are trying to use htmlwidgets::saveWidget on something that is not a widget. You should use htmltools::save_html instead; it knows how to write a Shiny tag list:

htmltools::save_html(myflex, "myflex.html")

Note that it will not create a self-contained page; it will write a list of Javascript libraries to a subdirectory (default name "lib"). If you want something self-contained, you should be able to use this code:

cat(repr::repr_html(myflex), file = "myflex.html")

but I'm not sure that's what it's intended for, so you might find problems.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Hello, I agree save_html works for creating a file. However, that file is not selfcontained such that it can be sent to a different location as the html file's dashboard does not populate in that case. When I manually save the file from Viewer pane > Export > Save as web page the file runs well. However I dont know how to invoke the same via script. Could you help with that? Thank you – Dominic Xavier Jan 31 '19 at 18:16
  • I've added an alternate solution. – user2554330 Jan 31 '19 at 19:58
  • That really helped a lot! Thank you so much! – Dominic Xavier Jan 31 '19 at 21:11