I have calculated the distances between cities through the google api service.
I need to get the distances into a distance matrix in R, but when I use the code:
de1 <- "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&destinations=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&mode=driving&language=en&sensor=false"
webpage1 <- getURL(de1)
webpage1 <- readLines(tc <- textConnection(webpage1)); close(tc)
pagetree <- htmlTreeParse(webpage1, error=function(...){})
If I then type "pagetree" I get an error message.
> pagetree
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<img src="//www.google.com/images/errors/logo_sm.gif" alt="Google">
</head>
<body>
<p><b>400.</b> <ins>Thatâs an error.</ins>
</p>
<p>Your client has issued a malformed or illegal request. <ins>Thatâs all we know.</ins></p>
</body>
</html>
Can somebody help me out?
Thank you,
sofia p.
try
require(RCurl)
webpage1 <- getURL(URLencode(de1))
also the data that is returned is in JSON format
require(RJSONIO)
data<-fromJSON(webpage1)
maybe useful
if you want xml returned try
require(XML)
de2 <- "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&destinations=Berlin|Hamburg|Muenchen|Koeln|Frankfurt am Mein|Duesseldorf|Bremen|Hannover|Nuernberg&mode=driving&language=en&sensor=false"
webpage2 <- getURL(URLencode(de2))
data2<-xmlParse(webpage2)
try package ggmap
library(ggmap)
mapdist(from, to, mode = c("driving", "walking", "bicycling"),
output = c("simple", "all"), messaging = FALSE, sensor = FALSE,
language = "en-EN", override_limit = FALSE)
Related
I have seen posts such as
Cypress - run test in iframe for how to handle iframes in Cypress. But I am using the old and outdated frames, which is what a legacy system (that I have to test) uses.
I have checked Github -Cypress iframes which is recommended by Cypress, but haven't found an answer for plain old frames. Using the solution for iframe, hasn't worked.
The problem is the same as with an iframe where, when trying to select an element using
cy.get('input').type('test');
you receive an AssertionError stating:
Timed out retrying after 4000ms: Expected to find element: input, but never found it.
Any advice is appreciated.
I don't have any experience with <frame>, but testing on this source
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example page</title>
</head>
<frameset cols="150,*">
<frame src="example_a.html">
<frame src="example_b.html">
<noframes>
<body>
<p>Alternate content</p>
</body>
</noframes>
</frameset>
</html>
example_b.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example page</title>
</head>
<body>
<input />
</body>
</html>
this test works
cy.visit('http://127.0.0.1:5500/index.html') // served from vscode
cy.get('frame')
.eq(1) // 2nd frame
.then($frame => $frame[0].contentWindow) // it's window
.its('document.body')
.within(() => { // sets cy.root() to 2nd frame body
cy.get('input')
.type('something')
.invoke('val')
.should('eq', 'something')
})
If you've got more complicated stuff to do, you can try visiting the frame's source, for example this makes the frame content the top window
cy.visit('http://127.0.0.1:5500/example_b.html')
cy.get('input')
.type('something')
.invoke('val')
.should('eq', 'something')
You can try something like this:
cy.get('#iframeSelector')
.then(($iframe) => {
const $body = $iframe.contents().find('body')
cy.wrap($body)
.find('input')
.type('test')
});
I have a code to send an image inline in body of email using sendmailR. However after receiving the email it does not contain the image. It shows the error : The linked image cannot be displayed.The file may have been moved,renamed or deleted.
Below is the code
library(sendmailR)
image<-"image.png"
body<-sendmailR::mime_part("<html><p>This is a picture.</p>
<img src='image.png' >
<p> Image is:</p>")
body[["headers"]][["Content-Type"]] <- "text/html"
sender <- "sender email"
recipients <- "receiver email"
subject <- "Test Email"
sendmailR:: sendmail(sender, recipients, subject, list(body),control=list(smtpServer="server address"))
The image is in the same folder as the rmd file.
Thank you.
I had the same question and I finally got it. Using your code should be something like:
library(sendmailR)
attachmentPath <-paste(getwd(),"/image.png",sep="")
attachmentObject <-mime_part(x=attachmentPath,name="plot.png")
msg <- mime_part('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style type="text/css">
</style>
</head>
<body>
<h1>HTML email</h1>
<img src="cid:plot.png" >
</body>
</html>')
msg[["headers"]][["Content-Type"]] <- "text/html"
body <- list(msg,attachmentObject)
sender <- "sender email"
recipients <- "receiver email"
subject <- "Test Email"
sendmailR:: sendmail(sender, recipients, subject, body,control=list(smtpServer="server address"))
as you can see you must reference the image using cid
Ask Question
0
I have just installed the atom editor along with the p5 manager package using The Coding Train’s videos. I am trying to use Atom-live-server to view my code. However, when I hit “Start Server”, it opens up a new tab, with the server name, and doesn’t show any of what my code is supposed to do. Activating Javascript console ju
00%20AM Screen Shot 2019-06-20 at 10.54.00 AM.jpg 2173×1134 241 KB st shows the following message: p5.sound.js:211 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio (anonymous) # p5.sound.js:211 p5.sound.js:4247 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio Tone.Context # p5.sound.js:4247 (index):53 Live reload enabled.
![40%20AM|466x313]
My sketch.js code is:
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(255,255,255);
console.log(“HELLO”);
print(“HELLO”); }
My index.html code is:
robby1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>robby1</title>
<script src="sketch.js"></script>
<script src="libraries/p5.js"></script>
<script src="libraries/p5.dom.js"></script>
<script src="libraries/p5.sound.js"></script>
<link rel="shortcut icon" href="">
<style>
body {
margin:0;
padding:0;
overflow: hidden;
}
canvas {
margin:auto;
}
</style>
</head>
<body>
</body>
</html>
To clarify, I am using chrome on a macOS mojave. I am unfamiliar with html, but know p5.js.
I have an image at the URL http://192.168.1.53/html/cam.jpg (from a Raspberry Pi) and this image is changing very fast (it is from a camera).
So I want to have some JavaScript on a website that will reload this image every second for example.
My HTML is:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pi Viewer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
<style>
img,body {
padding: 0px;
margin: 0px;
}
</style>
<img id="img" src="http://192.168.1.53/html/cam.jpg">
<img id="img1" src="http://192.168.1.53/html/cam.jpg">
<script src="script.js"></script>
</body>
</html>
And my script:
function update() {
window.alert("aa");
document.getElementById("img").src = "http://192.168.1.53/html/cam.jpg";
document.getElementById("img1").src = "http://192.168.1.53/html/cam.jpg";
setTimeout(update, 1000);
}
setTimeout(update, 1000);
alert is working, but the image is not changing :/ (I have 2 images (they are the same))
The problem is that the image src is not altered so the image is not reloaded.
You need to convince the browser that the image is new. A good trick is to append a timestamp to the url so that it is always considered new.
function update() {
var source = 'http://192.168.1.53/html/cam.jpg',
timestamp = (new Date()).getTime(),
newUrl = source + '?_=' + timestamp;
document.getElementById("img").src = newUrl;
document.getElementById("img1").src = newUrl;
setTimeout(update, 1000);
}
I am using below code to share the data frame "my_data1" with my friend and the code is working fine. But I have another data frame "my_data2" that I want to share. Please suggest where and how should I add the second table in my code
library(sendmailR)
library(pander)
from <- "<me#gmail.com>"
to <- "<friend#gmail.com>"
subject <- "Important Report of the Day!!"
body <- "This is the result of the test:"
mailControl=list(smtpServer="ASPMX.L.GOOGLE.COM")
#-----------------------------------------------------
#-----------------------------------------------------
msg_content <- mime_part(paste('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body><pre>', paste(pander_return(pander(my_data1, style="multiline", caption = "Net Bookings")), collapse = '\n'), '</pre></body>
</html>'))
msg_content[["headers"]][["Content-Type"]] <- "text/html"
sendmail(from=from,to=to,subject=subject,msg=msg_content,control=mailControl)
Adding <p><pre>', paste(pander_return(pander(my_data2, style="multiline", caption = "New Caption")), collapse = '\n'), '</pre> between </pre> and </body> should give you the desired result.
When you want to insert some text between the two tables, you can do:
<p>the text you want to insert between the tables</p>
<pre>', paste(pander_return(pander(my_data2, style="multiline", caption = "New Caption")), collapse = '\n'), '</pre>