Archiv der Kategorie: Software

How to scrape a website with R II: WYSIWYG

Part II

Although Rselenium allows a screenshot of the current browser window

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4444,
  browserName = "Chrome"
remDr$screenshot(display = T) # remDr$screenshot(file="screen.jpg")

I found it extremely difficult to control a webbrowser running in a Docker container – looking up the DOM tree, injecting javascript etc is a lot of guess work.

So we need also a VNC server in the docker container as found at github.

After starting in the terminal

docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-beta-1-prerelease-20210207

we can watch live at vnc:// what’s going on.

Breaking up long chains in R’s margrittr code and calling sub functions

Having several long and redundant chains in R ‘s margittr code, I have now figured out how to pipe into named and unnamed functions

f1 <- function(x) {
  x %>% count() %>% print()
f2 <- function(x) {
  x %>% tibble() %>% print()

So we have now two named functions with code blocks that can be inserted in an unnamed function whenever needed

iris %>%
  # do any select, mutate ....
  # before running both functions
  (function(x) {
    x %>% select(Species) %>% f1() %>% print()
    x %>% f2() %>% print()

How to save a Twitter thread

This is not a trivial task as most browser produce garbage when printing to pdf. Also screenshots do not help so much with multipage threads. “Unroll” also doesn’t work reliable.

So I have been using the plugin before producing the pdf,  but this method is time consuming  as it needs a captcha.

Having now Selenium running in a docker container, there is a more convenient solution where  just two lines of R are sufficient

remDr$screenshot(file = 'screen.png')

Login is also possible as explained at github

username <- remDr$findElement(using = "name", value = "session[username_or_email]")
passwd <- remDr$findElement(using = "name", value = "session[password]")
passwd$sendKeysToElement(list("XXX", "\uE007"))

RKI Daten sind tages- und nicht fallbasiert

Leider kann man mit den RKI Daten nicht direkt in ein Regressionsmodell gehen, weil an vielen Tagen mehr als ein Fall in derselben Kategorie auftritt RKI Daten sind tages- und nicht fallbasiert weiterlesen

How to scrape a website with R I: Using a browser generated cookie

While there are quite some SO examples out there how to manage the login, here are the ncessary steps whenever you need to login in manually and have to start with a browser cookie. First install the “EditThisCookie” plugin in Chrome and export the cookie How to scrape a website with R I: Using a browser generated cookie weiterlesen

Better than a streamdeck: the Mac touchbar

I have been thinking to buy an Elgato Streamdeck as we have to lecture now also online during winter 2020.

While the Streamdeck mini would be a nice addition to the Elgato 4 K Camlink (that connects the Nikon) as well as the Epoc Cam software (that connects the Iphone) for easy switching input channels, I ultimately decided against this solution and just reconfigured the Touchbar for OBS using Better Touch Tool.



Live video projection over 30 meter

Here is a working hardware combination after several failed attempts – jerky moves, black screen, lost signal, color shifts.

Nikon Z6 – switch video toggle @back of camera for clean HDMI output, set video menu to 60 frames (to avoid display lag), setting c3 standby on. 1800€ incl FTZ.

Sirui VH-10X Fluid, 100€ used.

subtel external power supply for Z6 (only this one allows closing of battery compartment). 56€.

Rode VideoMicro Compact. 88€.

Elgato Cam Link 4K with short USB C connector (to avoid shear stress). 122€.

Macbook Pro with USB-C Digital-AV-Multiport-Adapter (other display port and hdmi did not show up as external display in OBS). adapter 72€.

PW-HT225PIR HDMI Extender with power adapter (USB power alone not sufficient, HDMI amplifier failes consistently). 30€.

30m Cat6 cable. 30€.

Short throw Optoma UHD42 4K Beamer – UHD. 1200€

Science integrity consultants

Inclusion on the list does not mean to endorse or promote any company or individual

Resis (Enrico Bucci, but watch current Lancet controversy)

Science Integrity Digest (Elisabeth Bik, the most famous image spotter)

Image integrity (Jana Christopher, long-term expert)

Image Data Integrity (Mike Rossner, long-term expert as well)

plus many more individuals highlighted at

Laborjournal einzelne Artikel archivieren

Ist ganz einfach. Neuestes Heft herunterladen und splitten

# brew install ghostscript
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dFirstPage=6 -dLastPage=9 -sOUTPUTFILE=Krull.pdf LJ_20_07.pdf
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dFirstPage=14 -dLastPage=17 -sOUTPUTFILE=Antes.pdf LJ_20_07.pdf
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dFirstPage=26 -dLastPage=29 -sOUTPUTFILE=Jaeger.pdf LJ_20_07.pdf
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dFirstPage=34 -dLastPage=37 -sOUTPUTFILE=Jeschke.pdf LJ_20_07.pdf

Unter MacOS Keynote streamen mit Video

  1. OBS installieren mit Virtual Camera Plugin
  2. Powerpoint/Keynote als HTML exportieren und in lokalem Browser aufrufen
  3. OBS Template erstellen mit Text, Kamerainput und Browserwindow
  4. Virtual Camera in OBS starten
  5. In zweitem Browserwindow Konferenz starten und Einstellungen > Sicherheitscheck > Website > Einstellungen > Konferenz > Virtual Camera auswählen


  1. OBS installieren
  2. Keynote in Fenster wiedergeben
  3. OBS Template erstellen mit Text, Kamerainput und Fensterinput


Graphical display of outbreaks: Transmission trees

Let’s start with some examples from the literature, find out necessary elements, compare different versions and develop a R template for general use.

“Exploding Stars”

CDC Field Epidemiology Handbook, 2019, ISBN 9780190933692 p115

“Tetris” (2020)

“Clean Undeterministic”
“Clean Tree”

“Tree Addons”


“Simple ”


“star bus”



From R to Python

It’s bit confusing if you are having long-term experience with R but need some OpenCV Python code. What worked for me

  1. download and install Python 3.8.3.
  2. pip install opencv-python
  3. pip install opencv-contrib-python
  4. although Spyder or Jupyter is recommended for data science, I went for PyCharm
  5. install Atom and follow the video instructions
  6. take care, numerous non working introductions out there, stick to recent version

R leaflet – keep map in frame after closing info box

Although having some experience with leaflet before, it took me 5 hours to find out how to
(1) change the background color and
(2) re-center my map after the popup was panning the map  basically out view. Here is my solution

leaflet(options = leafletOptions(
 zoomControl = FALSE,
 minZoom=6, maxZoom=6,
 centerFixed = TRUE) ) %>%
addPolygons(data = ds,
 fillColor = ~pal(AnzahlFall),
 color="black", weight = 1,
 fillOpacity = 0.7,
 label = ~name_2,
 popup = ~www,
 popupOptions = popupOptions( autopan=FALSE, keepInView = TRUE ) ) %>%
 function(el, x) {
  var myMap = this;
  myMap.on('popupclose', function(e) { myMap.panTo( {lon: 10.26, lat: 51.1} ) });
  var e = document.getElementsByClassName('leaflet-container');
  e[0].style.backgroundColor = 'white';	    

python3 cv2 installation

Homebrew is struggling with the older python 2.7 version that is missing ssl support. Python 3.8 did not recognize cv2 but this finally worked

brew install python3
brew postinstall python3
pip3 install virtualenv virtualenvwrapper
virtualenv env_name --python="python3"
/Users/wjst/env_name/bin/pip3 install opencv-python
/Users/wjst/env_name/bin/pip3 install pandas scipy matplotlib Pillow tqdm sklearn imageio
/Users/wjst/env_name/bin/python3 -c "import cv2"

then I could finally run the image forgery detection from Github.

cd /Users/wjst/Desktop/image-copy-move-detection-master
> from copy_move_detection import detect
> ...