dataExplorer::create_report produces html file that is blank - html

I am trying to create a HTML report from the DataExplorer::create_report(). The code is as follows
DataExplorer::create_report(iris, config = list(add_plot_qq = FALSE, global_ggtheme = quote(theme_minimal(base_size = 14))))
The code creates "report.html", which is blank when I open it in any browser. I am using the DataExplorer version 0.8.0

Nick's answer is correct. I made some updates in v0.8 to simplify report customization, i.e., #87. However, I would like to use this section to provide a little more information on that. Please do not accept this as an answer.
configure_report helps you write less code in terms adding/removing sections, as well as editing themes. However, the output is no different from the list output from previous versions. If you want, you can still make your own list files and pass it to create_report. The template is here:
config <- list(
"introduce" = list(),
"plot_intro" = list(),
"plot_str" = list(
"type" = "diagonal",
"fontSize" = 35,
"width" = 1000,
"margin" = list("left" = 350, "right" = 250)
),
"plot_missing" = list(),
"plot_histogram" = list(),
"plot_qq" = list(sampled_rows = 1000L),
"plot_bar" = list(),
"plot_correlation" = list("cor_args" = list("use" = "pairwise.complete.obs")),
"plot_prcomp" = list(),
"plot_boxplot" = list(),
"plot_scatterplot" = list(sampled_rows = 1000L)
)
After that, you can just call create_report as usual:
create_report(iris, config = config)
Hope this helps!

For those searching for the answer use: config = configure_report() instead of config = list()
DataExplorer::create_report(iris,
config = configure_report(add_plot_qq = FALSE,
global_ggtheme = quote(theme_minimal(base_size = 14))))

Related

Is it possible to arrange graphs and filters in an R plot output?

I have created a small dashboard using bscols( from the crosstalkpackage. It consists of plotly graphs and their respective filter_checkboxes.
It looks pretty messy now, as the filters are not vertically aligned with their corresponding plots.
HTML_graphic
As indicated, I would like the first two checkbox sets to appear next to the second line graph (nothing to appear next to the first line graph); and the second two checkbox sets to appear next to the third line graph.
Also, I would like to create some vertical space between the three elements, as indicated by the brown and black horizontal lines.
The best solution would be to set the height of the html elements inside the bscols() command. Because in the future, I would like to programmatically save multiple of these outputs using htmltools::save_html.
The next best would be to have the output of that command somehow converted to html and add html code like line breaks or heights.
Neither I know how to do.
I came across this related question but it is unanswered: Arrange crosstalk graphs via bscols
Any suggestions on how to solve my problem?
My code
{r 002_Auto App Doc Vol_Invoice group delta plot - plot code, echo = FALSE}
# Setup of the legend for invoice plot
invoice_plot_legend <- list(
font = list(
family = "sans-serif",
size = 12,
color = "#000"),
title = list(text="<b> Delta previous month by division </b>"),
bgcolor = "#E2E2E2",
bordercolor = "#FFFFFF",
borderwidth = 2,
layout.legend = "constant",
traceorder = "grouped")
# The Shared Data format is needed for crosstalk to be able to filter the dataset upon clicking the checkboxes (division filters):
shared_invoice <- SharedData$new(Auto_App_Doc_Vol_invoiceg_plotting_tibble)
shared_invoice_KPI <- SharedData$new(Auto_App_Doc_Vol_KPI)
shared_abs <- SharedData$new(Auto_App_Doc_Vol_plotting_tibble_diff_abs)
# Setup of a bscols html widget; widths determines the widths of the input lists (here, 2: the filters, 10: the plot and legend)
# Overall KPI and invoice group plot
library(htmlwidgets)
crosstalk::bscols(
widths = c(2, 10),
list(
crosstalk::filter_checkbox("Division",
label = "Division",
sharedData = shared_invoice,
group = ~Division),
crosstalk::filter_checkbox("Rechnungsgruppe",
label = "Invoice group",
sharedData = shared_invoice,
group = ~Rechnungsgruppe),
crosstalk::filter_checkbox("Rechnungsgruppe",
label = "Invoice group",
sharedData = shared_abs,
group = ~Rechnungsgruppe),
crosstalk::filter_checkbox("Division",
label = "Division",
sharedData = shared_abs,
group = ~Division)
)
,
list(
plot_ly(data = shared_invoice_KPI, x = ~Freigabedatum_REAL_YM, y = ~KPI_current_month, meta = ~Division,
type = "scatter",
mode = "lines+text",
text = ~KPI_current_month,
textposition='top center',
hovertemplate = "%{meta}",
color = ~Diff_KPI_pp)
%>%
layout(legend = invoice_plot_legend,
title = "Automatically Approved Document Volume",
xaxis = list(title = 'Release date'),
yaxis = list(title = '%'))
,
plot_ly(data = shared_invoice, x = ~Freigabedatum_REAL_YM, y = ~n,
type = "scatter",
mode = "lines",
text = ~Rechnungsgruppe_effort,
hoverinfo = "y+text",
color = ~Difference_inline
)
%>%
layout(legend = invoice_plot_legend,
title = " ",
xaxis = list(title = 'Release date'),
yaxis = list(title = '# of Approved Documents'))
,
plot_ly(data = shared_abs, x = ~Freigabedatum_REAL_YM, y = ~n,
type = "scatter",
mode = "lines",
text = ~Lieferantenname,
hoverinfo = "y+text",
color = ~Lieferantenname_text
)
%>%
layout(legend = vendor_plot_legend,
title = "by vendor absolute delta previous month all documents",
xaxis = list(title = 'Release date'),
yaxis = list(title = '# of Approved Documents w/ & w/o effort')
)
)
)
Thank you so much!

R Obtaining a self-contained html file for tag list

I hope somebody can help me with this. I have a package that uses htmltools and reactable to produce html reports for some operations, for example:
columns_def <- list(
ProjectID = reactable::colDef(
align = "right",
style = list(
color = "#9e9e9e",
fontWeight = "800",
borderRight = "2px solid #E6E6E6"
),
minWidth = 60
),
concatenatePoolIDSeqRun = reactable::colDef(
minWidth = 100
),
Found = reactable::colDef(
maxWidth = 100,
align = "center",
style = function(value) {
color <- if (value == TRUE) {
"#6afc21"
} else {
"#d61e1e"
}
list(
color = color, paddingLeft = "15px",
fontWeight = "bold"
)
},
cell = function(value) {
if (value == TRUE) "\u2713" else "\u2718"
}
),
Path = reactable::colDef(
minWidth = 200
)
)
styled_df <- .generate_react_table(checker_df,
defaultSorted = list(Found = "asc"),
columns = columns_def
)
widget_text <- htmltools::tags$html(
htmltools::tags$head(
htmltools::tags$style(.widget_css())
),
htmltools::tags$body(
htmltools::h1("IMPORT ASSOCIATION FILE REPORT"),
htmltools::h2("ALIGNMENT RESULTS"),
htmltools::div(
id = "section-content",
htmltools::div("Results of alignment between file system and",
"association file. If some folders are not found",
"they will be ignored until the problem is fixed",
"and the association file re-imported.",
id = "subtitle"
)
)
)
)
widget <- htmlwidgets::prependContent(styled_df, widget_text)
In this case i'm using the prependContent function from htmlwidget since reactable is a widget. When I print this widget (either in RStudio Viewer or the browser) everything works fine, but I'd also like to export this widget in a self contained html file on disk at a specified path. So in my function code I do:
htmlwidgets::saveWidget(widg, export_widget_path)
From documentation by default the selfcontained parameter is set to TRUE and I have pandoc installed correctly but this happens:
Even if I opt for self contained options a files folder is produced and when I open the file a portion of it is wrongly rendered:
This doesn't happen when the widget is printed (either in viewer or browser)
I also tried to change this
widget_text <- htmltools::tags$html(
htmltools::tags$head(
htmltools::tags$style(.widget_css())
),
htmltools::tags$body(
htmltools::h1("IMPORT ASSOCIATION FILE REPORT"),
htmltools::h2("ALIGNMENT RESULTS"),
htmltools::div(
id = "section-content",
htmltools::div("Results of alignment between file system and",
"association file. If some folders are not found",
"they will be ignored until the problem is fixed",
"and the association file re-imported.",
id = "subtitle"
)
)
)
)
widget <- htmlwidgets::prependContent(styled_df, widget_text)
with this
widget <- htmltools::tags$html(
htmltools::tags$head(
htmltools::tags$style(.widget_css())
),
htmltools::tags$body(
htmltools::h1("IMPORT ASSOCIATION FILE REPORT"),
htmltools::h2("ALIGNMENT RESULTS"),
htmltools::div(
id = "section-content",
htmltools::div("Results of alignment between file system and",
"association file. If some folders are not found",
"they will be ignored until the problem is fixed",
"and the association file re-imported.",
id = "subtitle"
)
), styled_df
)
)
Obtaining a tag.shiny object but of course it doesn't work with htmlwidgets::saveWidget, I have to use htmltools::save_html which doesn't produce a self-contained file.
I know there is an option with pandoc to convert html to self contained but it also produces weird results when I tried to use it (mainly graphics not rendered correctly).
Is there any way this could be done or do I have to surrender to the fact that I'll have non self-contained html files? Thanks in advance
Have you tried setting your working directory to the location that you want to save the self-contained file? That is the only way that I am able to make self-contained files with htmlwidgets::saveWidget().
You need to use htmlwidgets::saveWidget(frameableWidget(mapdt3),'map.html') frameableWidget will be from widgetframe It will save the html file as self contained file.

Overwrite colorbar labels Bokeh

I tried to overwrite the colorbar labels, though I can not get it done, if someone could find out what is wrong in the code and let me know, it would be very appreciate. I can share the data if necessary. I also would like to know if it is possible to use widgets SELECT to select which county and hide the others, as callback.
Regards
palleteG = ['#39FF14', '#4CBB17', '#50C878', '#00A572','#2E8B57', '#0b6623'] #'#98FB98','#ffffff','#D0F0C0'
#color_mapper = LinearColorMapper(palette = palleteG, low = 25000, high = 450000)
color_mapper = LinearColorMapper(palette = palleteG, low = irl['2016'].min()*1.01, high = irl['2016'].max()*1.01)
color_bar = ColorBar(color_mapper=color_mapper, label_standoff=6,
width=500, height=20, border_line_color=None,
location='center', orientation='horizontal',
major_label_overrides=tick_labels,
bar_line_color='#50C878',
bar_line_alpha=0.7)
ps = figure(title = 'Irish Housing Stock 2016', tools = 'pan, wheel_zoom, box_zoom, reset, hover, save',
tooltips = [('County', '#COUNTY'),('Housing Stock','#2016'), ('Population','#Population'),
('Number of Social Housing necessary','#Solution')], #,],
x_axis_location = None, y_axis_location = None, plot_width=600, plot_height=800)
ps.patches('xs', 'ys', fill_alpha = 0.7, fill_color = {'field':'2016', 'transform':color_mapper}, line_color = 'black', line_width = 0.5,
source = geo_source) # fill_color = 'green'
ps.grid.grid_line_color=None
ps.add_layout(color_bar, 'below')
show(ps)
output_file('IHS.html', mode='inline')
The challenge now it's find the right tune for the bar.

Converting LDAvis output to tiff

I'm working on topic modeling and I've recently discovered the excellent library 'LDAvis'. Unfortunately, the visual output of the library is in json, and I do not know how to convert it to tiff. This is the format required for graphs by most academic journals.
What I need is a way to convert the output of LDAvis to tiff.
Here an example I've derived from the 'text2vec' package, from here: https://github.com/dselivanov/text2vec/issues/235
library(text2vec)
library(magrittr)
data("movie_review")
tokens = movie_review$review[1:4000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, ids = movie_review$id[1:4000], progressbar = FALSE)
v = create_vocabulary(it) %>%
prune_vocabulary(term_count_min = 10, doc_proportion_max = 0.2)
vectorizer = vocab_vectorizer(v)
dtm = create_dtm(it, vectorizer, type = "dgTMatrix")
lda_model = LDA$new(n_topics = 10, doc_topic_prior = 0.1, topic_word_prior = 0.01)
doc_topic_distr =
lda_model$fit_transform(x = dtm, n_iter = 1000,
convergence_tol = 0.001, n_check_convergence = 25,
progressbar = FALSE)
# this plots LDAvis in current session
lda_model$plot()
What I want to accomplish are graphs like this:
and this:
Unfortunately, this is the best I can do, by using of some kind of converter (press "print" the page, and it opens automatically, as a .pdf converter)
Thank you in advance.

Need help in scraping the img src from a website; below is my code

Below is my web scraping code for a website; it clicks a form which redirects to a page. From that page I need to extract [img] src url and export it into csv in a text form. I used the code below to extract a content from a td tag. When I run the same code it doesn't work because the td tag has no content but only a img tag. Any help will be appreciated. I am new to web-scraping. Thanks in Advance.
browser.find_element_by_css_selector(".textinput[value='APPLY']").click()
#select_finder = "//tr[contains(text(), 'NB')]//a"
select_finder = "//td[text()='NB')]/../td[2]/a"
browser.find_element_by_css_selector(".content a").click()
assert "Application Details" in browser.title
file_data = []
try:
assert "Application Details" in browser.title
enlargement = browser.find_element_by_xpath("/html/body/center/table[15]/tbody/tr[3]/td[2]/b").text
enlargement_answer1 = browser.find_element_by_xpath("/html/body/center/table[15]/tbody/tr[4]/td[2]").text
enlargement_answer2 = browser.find_element_by_xpath("/html/body/center/table[15]/tbody/tr[4]/td[3]").text
enlargement_text = enlargement + enlargement_answer1 + enlargement_answer2
considerations = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[4]/td[2]/b").text
considerations_answer = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[4]/td[3]").text
considerations_text = considerations + considerations_answer
alteration = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[4]/td[6]/b").text
alteration_answer = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[4]/td[7]").text
alteration_text = alteration + alteration_answer
units = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[5]/td[3]/b").text
units_answer = browser.find_element_by_xpath("/html/body/center/table[15]/tbody/tr[5]/td[4]").text
units_text = units + units_answer
occupancy = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[6]/td[3]/b").text
occupancy_answer = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[6]/td[4]").text
occupancy_text = occupancy + occupancy_answer
coo = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[7]/td[3]/b").text
coo_answer = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[7]/td[4]").text
coo_text = coo + coo_answer
floors = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[8]/td[3]/b").text
floors_answer = browser.find_element_by_xpath("/html/body/center/table[16]/tbody/tr[8]/td[4]").text
floors_text = floors + floors_answer
except (NoSuchElementException, AssertionError) as e:
floors_text.append("No Zoning Characteristics Present")
coo_text.append("n/a")
occupancy_text.append("n/a")
units_text.append("n/a")
alteration_text.append("n/a")
considerations_text.append("n/a")
enlargement_text.append("n/a")
with open('DOB.csv', 'a') as f:
wr = csv.writer(f, dialect='excel')
wr.writerow((block_number, lot_number, houseno, street, condo_text,
vacant_text, city_owned_text, file_data, floors_text, coo_text, occupancy_text, units_text, alteration_text,
considerations_text, enlargement_text ))
browser.close()
As you stated you are new to web scraping I encourage you to read up a bit: http://selenium-python.readthedocs.io/locating-elements.html
You are using XPath exclusively and in ways that are not recommended.
From the docs: "You can use XPath to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute."
Try using other locators to get your image.
for example: driver.find_element_by_css_selector("img[src='images/box_check.gif']")