Factsheets from R - cat(), flexdashboard() or Markdown? - html

I am looking to create Factsheets to demonstrate standardized information for about 20 projects. I want this information to be updated weekly (to observe progress) and be an HTML file. I was thinking of creating something like this: http://htaindex.cnt.org/fact-sheets/?focus=cbsa&gid=741
I have three options I could use:
The frenkenstein approach: I could write all the html for a dummy factsheet, then mush my data into it in R and output the file with cat(). If I really wanted to be fancy I could even define custom functions that would elegantly mush the data together with html so that the implementers wouldn't have a heart attack at the wall of html and css.
The limited approach: I could use flexdashboards which allows for assets to be placed in row or column orientation but not really a combination. This would limit my creative options, but is much faster and more reproducible, debuggable, etc
The correct approach: I guess people will say that I should build a markdown template as documented here, but that seems incredibly time-intensive and it looks as though I would have to get very familiar with pandoc, which I'm not looking forward to.
My question (hopefully not too wide) then is: Why shouldn't I just use the Frankenstein approach?

Related

How to store html document in sql?

I am considering to store my html document in table like this:
id content parent tag
1 0 html
2 1 head
3 1 body
4 Main page 2 title
5 Hello world 3 h1
This is just simplistic example. The result should be
<html>
<head>
<title> Main page </title>
</head>
<body>
<h1> Hello world </h1>
</body>
</html>
Right now, I am able to use CTE with SQL to have query resulting in correct tree structure. My idea was inspired by this page:
https://www.sqlite.org/lang_with.html
(Scroll down for the best part as solving sudoku with sql.)
I want to use sql as most as possible to avoid php code for my reasons. My questions are like this:
Do you have any idea to finish the process? (E.g. map html tags, orderings, inserting and deleting nodes etc). Any thoughts would be appreciated.
Did you try (or see) anything similar? Personal experiences, tutorials and so on?
How would you suggest to make table structures? For example to avoid repeating of same html structures (typically headers, menus, footers)?
Anything else what could be useful and related to this topic?
I hope you find this topic as intriguing as me :)
PS: I want to use SQLite but I think it doesnt matter if you wont suggest anything too much database specific
PPS: Please read before you advice it is not good idea :)
I would like to make most part of project in sql. It is my time to waste so dont worry :)
It is just experimental thing. I would use python instead of php if the choice of language was that important. Basically, as you have ORM to have database-independent apps I am trying to make opposite - to have language independent sql database accessed just by any language. That is my target more or less.
Speaking of wasting my time I could say the very same for the poor ones who are involved in any php frameworks. Recently, I had checked few of them and from my perspective I would call waste of time something really different :)
There's a number of ways to store a tree structure in an RDBMS. HTML, though, is not a perfect tree structure. You'll face numerous issues creating valid HTML from your data (should <p> be closed? should selected attribute have a value? etc).
Also, SQL is not exactly a language to easily manipulate trees. In other words, any non-trivial editing of your template in the database would be a huge pain.
So I suppose you want to serialize a DOM tree, which you know how to produce from a regular HTML file, to save time on parsing. You can as well store it not as a complete DOM tree but as a sequence of fragments, only adding children where the HTML template has loops. This will exclude most of the DOM hairiness: why painstakingly parse it first only to serialize back later?
This, BTW, will require the template itself be a well-formed tree: no conditionally closed tags or suchlike. Some templating engines require this.
I'd not store the thing as a tree. Instead I'd store a parsed template as a flat sequence of fragments with markers where a nested structure begins and ends. It would be trivial to load, trivial to process (all you need is a stack to keep track of nesting), and much easier to inspect with eyes and debug.
Or maybe you'll look around and find a ready-made templating engine that does just that. I've no idea what modern PHP landscape looks like, but chances to find an existing solution in such a mature environment are quite high.
If you still take the tree approach, make sure that you can load the entire tree in one query, because database round-trips are not so cheap, even for in-process SQLite.
But before you even continue with any approach, profile your code first. I bet that templating is not the bottleneck, and lowering the number of database / file system accesses will have a much more pronounced effect on latency and CPU load.

Mediawiki cross-page data access

Perhaps I'm going a bit overboard here, but I'm looking for a way to access data on a page of my Mediawiki install (call it Page1) and use that data on a second page (call it Page2). I know I can simply transclude the data, but I'm looking (I think) for a little more than that.
Basically, I'd like to get the data from Page1 and parse it in such a way that I can make it display nicely on Page2.
For a more specific example: I use Lingo to process on my glossary page (called Glossary), but I don't like the way the glossary displays. Furthermore, I'd like to be able to add definitions willy nilly without having to worry about alphabetizing them.
My desire is to parse the data in Glossary, and then show it formatted and alphabetized (as desired) in a separate page.
I figure that I can always write an extension that does this for me, but does something like this already exist? Is this something that is included in Semantic Wiki?
Yes, you can do that in SemanticMediaWiki. For an example of an advanced terminology wiki based on SemanticMediaWiki, see http://tieteentermipankki.fi/
As for Lingo, its markup appears to be very simplistic: https://www.mediawiki.org/wiki/Extension:Lingo#Usage But it allows transclusion, so you can just define each term on its own page, then transclude all the pages in your Terminology page, then transclude them in a different way and wrapped in all the formatting you desire.
Or any variation of the concept, possibly using templates with Lua modules if you need advanced and/or repetitive formatting.

Rotating quotes in Jekyll

I'm new to this Jekyll business but have tasted the massive potential of liquid - with this test personal website I'm building.
Getting to the point, I'd like rotating quotations, in the right hand box, of the type found at the top right of the veteran Oil Drum blog. (Check it out.)
I already have a stock of quotes separated by blank lines. What do I need to do to get my site to select them one by one and put a different one up every day/week/month?
Imagine the answer will involve some of the {{xx}} style code that is the trademark of the liquid template language, used by Jekyll.
Closest answer I could find was this btw - not satisfactory for my needs.
Cool rotating quote e.g.:
I think you can imitate the posts which are auto listed.
you can customize it by edit the list-make file at _include/JB/ to your wanted form.
And in this way you have to put your quotes to different file.
Maybe you can find exist implement to do it or write the program by yourself.
i'm sorry to make the complex way.
If setting this up with Liquid, the quote could only be changed by rebuilding the site (cron job if self hosting or something).
Alternatively if you need to make it update on it's own, there are JS solutions available. Quick google brought this up which gives a rotation, but it is not time based. https://stackoverflow.com/a/15614495/230449
It will be possible to do a time based solution in JS, but that is not my speciality.

Write formula in html

How to write formula in html page?
For example I need to write square root of x power 2 minus y. I know only one way, LaTex. But I need easier way. I'm writing quiz testing system. Students should write answer, that contains formula. How could I do this?
Check out MathJax, which is used on math.stackexchange.com.
The only two answers I know of for that are using images:
http://www.cs.tut.fi/~jkorpela/math/
...or using HTML math notation for that (although it is not that simple to use)
http://www.unics.uni-hannover.de/nhtcapri/mathematics.html
You also have this alternative, but it seems rather experimental...
http://www.w3.org/MarkUp/HTMLPlus/htmlplus_45.html
http://meta.wikimedia.org/wiki/Help:Displaying_a_formula
Still, I hope it helps...
This is a utility to write math (using LaTeX syntax) in HTML, but you also need to have LaTeX installed on your machine to generate the images of the formulas.
If you do not need to render the answer, just make it is correct, then the best way to go is probably to allow them to use something like sqrt(), ^ for power, etc..
I find this is the easiest way of writing if the input is for a machine.
You could just provide a small list of allowed functions with examples.
The bonus here would be that you can probably look around for a lib and use it to evaluate the answer.
So your example would be written like: sqrt(x^2)-y
Of course this can get very messy if you need to write complex equations but for the level you presented it should work fine.

multi language html page

The website I'm currently working on is supposed to be in multiple languages (4 in this case).
What's the "best" way to achieve this?
It seems like most people use a php table for it. Is this the "best" way right now?
Alas I only know some HTML and CSS, so my idea was to simply copy the whole website tree and make a seperate html tree for each language starting with index.html as the default language and three other trees starting with index_lang2.html, index_lang3.html, index_4.html.
On the index site you could switch the language and go down each seperate html tree.
Is this solution acceptable? I seems quite easy to generate but hard to maintain.
it depends on how much pages you have! There is no reason in making a language system if you only have 10 plain html pages and have no clue about php. And such systems are "only for" UI Elements and not for the real content if you plan to post information there...
If that are static pages, then using no such system is a nice solution!
But if you have more, then there are several solutions:
Take an existing Framework with language support
Write your own language class with vars on the different places
... there are for sure more possibilities, but nothing which comes in my mind :)
As already stated, I think as long as your site only has limited static HTML webpages then it's not worth trying to implement a fancy PHP solution (especially if you have to learn PHP to do so!)