1. home
  2. #tags
  3. HTML

Discover Latest #HTML News, Articles and Videos with Contenting

Breaking News Coronavirus Update: Vaccine Ready for Human Trials A vaccine for the novel coronavirus has been developed and is ready for human trials, according to the World Health Organization. The vaccine is a combination of two existing vaccines that have been modified to target the virus that causes COVID-19. Clinical trials will begin in the coming weeks and the vaccine could be ready for use by the end of the year. Read more here Article: How to Stay Positive During Coronavirus Outbreak The coronavirus pandemic has upended our lives and left us feeling anxious, uncertain, and overwhelmed. But despite the difficult times, it is important to stay positive. Here are some tips for doing just that: Focus on what you

Secure your website wherever you are (Sponsored by SSLs.com)

Show your company is legit, from $36.88ad

Buy a domain and everything else you need (Sponsored By namecheap.com)

adad

Getting My Feet Wet With `Plumber` and JavaScript | R-bloggers

Tried out plumber and a bit of JavaScript to build a simple local API for logging migraine events 🧠💻. Just a quick tap on my phone now records the time to a CSV—pretty handy! 📱✅ Motivation After our previous blog on barometric pressure monitoring, my friend Alec Wong said ‘Won’t it be great if we can just hit a button and it will record an event?". In this case the reason for recording barometric pressure is to see if there is a link between migraine event and barometric pressure values/change etc. And yes, it would be great if we can create an app of something sort to make recording much easier! There are many ways to do this. The way where we can maximize learning within R environment is to use plumber to create an API for us to interact and record event! Our use case is actually quite straight forward. We just need something that record a current timestamp when a button is clicked. Simple! But since I’ve never used plumber before, this is a great opportunity to explore it! And also a bit of JavaScript too. Again, this blog is more for my benefit where it serves as a note for myself. Here we go! Objectives: Big Picture plumber.R How to run it? One Click on iOS Opportunities for Improvement Lessons Learnt Big Picture As the image above shows, we want an app on our phone that once clicked will somehow change a csv dataframe. All these can be done by plumber setting an API to the csv. Since I just want to be able to do this on a local network of a different device (e.g. raspberrypi), we don’t need to deploy this to digital ocean or a server per se. We can run it in the background and set systemctl in case rpi restarts, point it to 0.0.0.0 and we can GET/POST via the device’s IP. Yes, unfortunately this will not work if we’re no longer on local network, which at least from my utility, it will be just fine. No need to expose port forwarding. The safer way would be to use digital ocean droplet to do this, so you’re not exposing your own IP and open port to the public. That also means, you may have to pay some 💰 (e.g. ~$5/month). May someday when it can incorporate the barometric pressure and/or other metrics then plumber.R library(plumber) library(readr) file response.json()): This is a Promise chain. After the fetch request completes, this takes the response from the server and calls the .json() method on it, which parses the JSON response body into a JavaScript object. This method also returns a Promise that resolves to the parsed JSON data. .then(data => { const resultDiv = document.getElementById("result"); resultDiv.textContent = data[0]; resultDiv.style.display = "block";}): This is the next step in the Promise chain. Once the JSON is parsed, It finds the HTML element with the ID “result”. Sets its text content to be the first item in the data array (data[0]). Makes the element visible by setting its CSS display property to “block” .catch(error => { const resultDiv = document.getElementById("result"); resultDiv.textContent = error.message })};This catches any errors that might occur during the fetch operation or when processing the response. If an error happens, it finds the HTML element with ID “result”. Sets its text content to the error message. The interesting thing I’ve not come across is the arrow function. response => response.json() means function(response) { return response.json() }. More Plumber API functions: #* logging #* @post /log function(){ date_now