I have a map leaflet that I want to save in an html file in a specific folder.
I am using Windows 7.
I tried the following :
library(htmlwidgets)
saveWidget(map_leaflet, file="ressources/test.html")
library(htmlwidgets)
saveWidget(map_leaflet, file="ressources\\test.html")
library(htmlwidgets)
path_name <- file.path("ressources", "test.html", fsep="\\")
saveWidget(map_leaflet, file=path_name)
library(htmlwidgets)
path_name <- paste("ressources", "test.html", sep="/")
saveWidget(map_leaflet, file=path_name)
As an error message, depending on the Rstudio session, I either have
1) Error in setwd(dir) : cannot change working directory
2) Cannot find path
When I only save like this :
library(htmlwidgets)
saveWidget(map_leaflet, file="test.html")
It works perfectly.
Thank you in advance for your help.
Agreed.
here is a workaround:
f<-"ressources\\test.html"
saveWidget(map_leaflet,file.path(normalizePath(dirname(f)),basename(f)))
The issues appear to be that saveWidget does not work with relative pathnames and normalizePath does not work for paths to files that done exist yet.
I would call this a bug in saveWidget.
edit:
I have contribute what I think is an even better workaround to an existing open issue
I use the with_dir function in the withr package to do this. I also put it in a wrapper function:
save_leaflet <- function(plot, file, overwrite = FALSE){
# save the file if it doesn't already exist or if overwrite == TRUE
if( !file.exists(file) | overwrite ){
withr::with_dir(new = dirname(file),
code = htmlwidgets::saveWidget(plot,
file = basename(file)))
} else {
print("File already exists and 'overwrite' == FALSE. Nothing saved to file.")
}
}
Related
I downloaded https://github.com/jgraph/mxgraph open source code from Git,this application Save functionality not working in the locally. Is there any possible for run the save functionality in Locally?. is there any configuration required for that? please help me.
After save button click getting below error message
I provide the code snippets for local save && upload of the saved file
code to export the xml of the current graph object
let encoder = new mxCodec();
let result = encoder.encode(graph.getModel());
let xml = mxUtils.getXml(result);
//workaround for the xml export, do not include the <mxGraphModel> tags
xml = xml.substring(xml.indexOf("<mxGraphModel>")+"<mxGraphModel>".length, xml.indexOf("</mxGraphModel>"));
code to upload the xml to re-generate the saved state of the graph
let doc = mxUtils.parseXml(xml);
let codec = new mxCodec(doc);
codec.decode(doc.documentElement, graph.getModel());
let elt = doc.documentElement.firstChild;
let cells = [];
while (elt != null)
{
let cell = codec.decode(elt)
if(cell != undefined){
if(cell.id != undefined && cell.parent != undefined && (cell.id == cell.parent)){
elt = elt.nextSibling;
continue;
}
cells.push(cell);
}
elt = elt.nextSibling;
}
graph.addCells(cells);
You can save locally by using the mxCodec class found in the IO package. Check out the example code here.
I'm not sure how to tie it into that specific button, but find the function that is called when you click save and add/replace it with the three lines needed to encode as xml.
As for how to get that xml code to save as a file, I'm not sure. Perhaps you'll find that code when you modify the save button functionality. The easy way would be to create a div and replace its innerhtml with the xml data, then just copy it and save it yourself.
In mediawiki, I can show a link to a file using:
[[Media:File.pdf|A file]]
Results in
A file
But how can I get the the last modified date for an uploaded file? I would like to show the timestamp alongside that link, rather than having to go to the file page for it. Is there a way to do this?
A file [Timestamp]
Does this require an extension of some sort? I am unable to find any documentation on getting metadata for uploaded files.
It would require custom logic, yes (which is normally packaged into extensions but in simple cases you can just add it directly to your config file). You can use the HtmlPageLinkRendererEnd hook for example:
global $wgHooks;
$wgHooks['HtmlPageLinkRendererEnd'][] = function(
LinkRenderer $linkRenderer, LinkTarget $target,
$isKnown, &$text, &$attribs, &$ret
) {
if ( $linkTarget->inNamespace( NS_FILE ) ) {
$file = wfFindFile( $linkTarget->getText() );
if ( $file && $file->exists() && $file->isLocal() ) {
$text .= ' ' . $file->getTimestamp();
}
}
};
(untested) which will put the timestamp inside the link but it's close enough.
Currently I am using the solution provided by this answer in my file upload page. But using the solutions here I found that when the file type is switched to All files, all files of any type is shown and able to upload. (I mean once we clicked the file upload button window is appeared showing our local directories. There is an option at the bottom right corner to change the file type) How do I prevent it?
Finally found this Javascript function which works fine.
var fl = document.getElementById('file');
fl.onchange = function(e){
var ext = this.value.match(/\.(.+)$/)[1];
switch(ext)
{
case 'mp4':
case 'mov':
case 'mpg':
case 'avi':
alert('allowed');
break;
default:
alert('not allowed');
this.value='';
}
};
I am trying to addapt the code found in
Python + Selenium + PhantomJS render to PDF
so I instead of saving one web page as a pdf file, I can iterate over a list of urls and save each one with a specific name (from another list).
count = 0
while count < length:
def execute(script, args):
driver.execute('executePhantomScript', {'script': script, 'args' : args })
driver = webdriver.PhantomJS('phantomjs')
# hack while the python interface lags
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
driver.get(urls[count])
# set page format
# inside the execution script, webpage is "this"
pageFormat = '''this.paperSize = {format: "A4", orientation: "portrait" };'''
execute(pageFormat, [])
# render current page
render = '''this.render("test.pdf")'''
execute(render, [])
count+=1
I tested modifying
render = '''this.render("test.pdf")'''
to
render = '''this.render(names[count]+".pdf")'''
so as to include the each name in the list using count but have not been successful.
Also tried:
dest = file_user[count]+".pdf"
render = '''this.render(dest)'''
execute(render, [])
But did not work either.
I greatly appreciate a suggestion for the appropriate syntax.
It must be very simple but I am a noobie.
Use string formatting:
render = 'this.render("{file_name}.pdf")'.format(file_name=names[count])
I have trouble getting Cory's Collisiondetectionkit to work. I have installed it, and put the com folder in a random folder where I keep all my files. It looks like this:
but I get an error when I export the code below (along with a bit more code)
Call to a possibly undefined method checkCollisions
through a reference with static type Class
This is referring to the lines that says
if(CollisionLis...
below.
This is the code which I have imported it with:
import com.coreyoneil.collision.*;
and this is where I call it in the code:
if(oCharUse == true){
if(CollisionList.checkCollisions(b1, oChar) == true){
trace("collision")
}
The folder the com folder is located in looks like this:
You're using it wrong. The function will create an array of DisplayObjects that are colliding. For example, if b1 and oChar are colliding, trace(CollisionList.checkCollisions()[0].name); should trace b1 and trace(CollisionList.checkCollisions()[1].name); should trace oChar.
With what you're trying to achieve, you could replace
if(CollisionList.checkCollisions(b1, oChar) == true){
with
if(CollisionList.checkCollisions().indexOf(b1) && CollisionList.checkCollisions().indexOf(oChar)){
Source: https://code.google.com/p/collisiondetectionkit/