I'm sure I'm missing a basic issue but I'm not currently able to find my way out of this problem.
Is there a way to save a simple (not Shiny) Timevis timeline in html webpage from the code?
I've successfully tried by using RStudio export button but I would like to include the function in the code.
htmlwidgets::saveWidget() doesn't work properly as the webpage is incomplete e.g. zoom buttons are missing (see incomplete webpage print screen) even with a minimal code:
myTimeline<-timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12"))
)
htmlwidgets::saveWidget(myTimeLine,"myTimeLine.html")
Thank in advance for any help and advice!
There is an open issue on github about this.
The workaround is to use selfcontained = FALSE:
htmlwidgets::saveWidget(myTimeline, "myTimeLine.html", selfcontained = F)
If you want to use a selfcontained version (e.g. because you want to offer this htmlwidget via plumber), the issue is the lack of zoom buttons.
If you modify the output HTML content to re-include the zoom buttons properly, everything works fine.
Related
I am think to scape some data from the following webpage using selenim and beautiful soup. But when inspect the html I could not locate the page number link.
http://quote.eastmoney.com/center/boardlist.html#concept_board
Would greatly appreciate any help.
df_all=pd.DataFrame()
for j in range(1,18):
browser.get('http://quote.eastmoney.com/center/boardlist.html#concept_board')
mtable = browser.find_element_by_id('table_wrapper-table')
content = browser.find_element_by_class_name('paginate_input')
button_go = browser.find_element_by_link_text('GO')
content.clear()
content.send_keys(str(j))
time.sleep(2)
browser.find_element_by_link_text('GO').click()
time.sleep(5)
mtable = browser.find_element_by_id('table_wrapper-table')
for row in mtable.find_elements_by_css_selector('tr'):
i=0
for cell in row.find_elements_by_tag_name('td'):
i+=1
if i==2:
print(cell.text, cell.find_elements_by_css_selector("a")[0].get_attribute("href"))
Ok, a couple of things here:
You are trying to get a url, but didn't provide the proper sytanx. There is no http protocol provided (see below code)
I am not sure if you are trying to locate just a page number, or trying to click on the next page and so on, you click on Go button.
Here is the code until what you have provided.
driver.get("https://quote.eastmoney.com/center/boardlist.html#concept_board")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'paginte_go')).click() # to locate to 'Go' button and click on it to go to next page
I am not sure why code format is not working today. I am sorry for this text-ish style of format
I need to create a pdf preview that should be displayed on a web page as an image. The pdf file is just a simple report build on almost plain HTML. Essentially I had a problem with displaying checkboxes, now I replaced them with pics of checkboxes but the issue remains the same.
Here how I create the pdf report from my HTML view with help of groovy and grails:
def html = htmlRenderService.getReport(info)
ByteArrayOutputStream out = new ByteArrayOutputStream()
HtmlImageGenerator htmlImageGenerator = new HtmlImageGenerator()
htmlImageGenerator.loadHtml(html)
BufferedImage bi = htmlImageGenerator.bufferedImage
ImageIO.write(bi, "PNG", out)
byte[] bytes = out.toByteArray()
String base64bytes = encoder.encodeToString(bytes)
String src = "data:image/png;base64," + base64bytes
out.flush()
def getReport(Info info) {
return groovyPageRenderer.render(view: REPORT_VIEW,
model: [info: info])
}
Then I send the src string to my view and render it as:<img src="${src}" alt=""/>
Then my checkbox pic looks like this: <div style="/*style stuff*/ background-image: url(data:image/png;base64,LINK_TO_THE_IMAGE"></div>
In the end, I received a picture of my pdf report rendered pretty well displaying as an image on my page, BUT without checkboxes. Here is the picture of one part of it:
And here is the same part but from the pdf document which I rendered all the same way, but just downloaded directed from my webapp:
Here is an example where I combined both options(input checkbox and image checkbox) and rendered it as an image:
So what could cause this issue? Thank you in advance.
UPDATE: I came across today to this comment under another issue with HtmlImageGenerator:
HtmlImageGenerator seems to use a JEditorPane for rendering the HTML. Swing HTML support does not extend to the ability to render data images. It might be possible by digging into the HTMLEditorKit and changing the image loading element to support data images, but then you'd need to find a way to get HtmlImageGenerator to use the altered editor pane.
Seems that HtmlImageGenerator doesn't work well with images inside HTML files, but it's still unclear why it doesn't render checkbox inputs as well.
Without seeing the code you end up with after page load, check the chrome dev tools panel to see if the image has actually loaded correctly to the page which will tell you it's at least accessible to use. Then check if the url is output correctly to the div as the background-image. If it looks correct and there aren't related errors in the console, it is likely a css setting.
With background images, your container will need to contain content or else you will need to specify:
width
height
a display setting
background-position, and a
background-size
If you can upload more info, I might be able to be more specific.
I am working on some website automation. Currently, I am unable to access a nested html documents with Splinter. Here's a sample website that will help demonstrate what I am dealing with: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select
I am trying to get into the select element and choose the "saab" option. I am stuck on how to enter the second html document. I've read the documentation and saw nothing. I'm hoping there is a way with Python.
Any thoughts?
Before Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
# This is where I'm stuck. I cannot find a way to access the second (nested) html doc
innerframe = browser.find_by_name("iframeResult").first
innerframe.find_by_name("cars")[0]
Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
with browser.get_iframe("iframeResult") as iframe:
cars = iframe.find_by_name("cars")
cars.select("saab")
I figured out that these are called iframes. Once I learned the terminology, it wasn't too hard to figure out how it interact with it. "Nested html documents" was not returning the results I needed to find the solution.
I hope this helps someone out in the future!
How could I render a HTML widget (produced by dygraphs in my case) directly in an external browser (Chrome for instance)?
I guess I could save the widget, build a HTML page, link the widget to it and use something like browseURL.
I am looking for something more seamless and performance oriented. The equivalent of the "Show in new window" button within R Studio viewer would be perfect (but without having to render the graph in R Studio viewer in the first place).
-- EDIT
Thanks for your suggestion Tan. I have tried with Markdown, seemed simpler than Shiny. But it did not work. Any idea why? (I get a strange "!–html_preserve–" flag in output).
require(data.table)
require(knitr)
require(dygraphs)
dt = data.table(
ts = as.POSIXct( c('2010-01-01','2010-01-02','2010-01-03') ),
value=rnorm(3)
)
write( "```{r}\n dygraph(dt) \n```", file = "tmp.Rmd" )
knitr::knit2html('tmp.Rmd')
browseURL('tmp.html')
Thanks to Jonathan from RStudio for his answer here.
require(data.table)
require(rmarkdown)
require(dygraphs)
dt = data.table(
ts = as.POSIXct( c('2010-01-01','2010-01-02','2010-01-03') ),
value=rnorm(3)
)
write( "```{r}\n dygraph(dt) \n```", file = "tmp.Rmd" )
rmarkdown::render("tmp.Rmd")
browseURL("tmp.html")
You are looking for Shiny, not quite HTML but fits the bill in every other way. http://shiny.rstudio.com/
I am using knit to convert my .Rhtml file to an .html file.
I am calling the output of a chunk called Q1:
<!--begin.rcode Q1,echo=FALSE,fig.show="all",fig.align="center",warning=FALSE
end.rcode-->
Here comes the chunk, it is basically a ggplot2 figure in a 2x2 layout.
library(ggplot2)
myplot = list()
for (i in 1:4){
x = 1:100
y = sample(100,100)
data = data.frame(x=x,y=y)
myplot[[i]] = ggplot(data,aes(x=x,y=y))+geom_point()+labs(title="bla")}
do.call(grid.arrange,c(myplot,list(nrow=2,ncol =2)))
Now, when looking at the resulting html file, I would like to incorporate the following feature:
I would like to have a link (e.g. to a database) when clicking on the title of each plot.
Is this somehow possible?
Thx
This doesn't completely answer your question, but it might get you or someone else started on a full answer.
Paul Murrel's gridSVG package (see also this useful pdf doc) allows one to add hyperlinks to grid-based SVG graphics. (In theory it should thus work with ggplot2; in practice I've just got it working with lattice). The current issue of the R Journal includes a couple of articles ("What's in a name?" and "Debugging grid graphics." -- Warning: pdfs) that might help you to best design dynamic searches for name of the grob to which you'd like to add a link (as in my second line of code).
library(gridSVG)
library(lattice)
xyplot(mpg~wt, data=mtcars, main = "Link to R-project home")
mainGrobName <- grep("main", grid.ls()[[1]], value=TRUE)
grid.hyperlink(mainGrobName, "http://www.r-project.org")
gridToSVG("HyperlinkExample.svg")