-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
148 lines (120 loc) · 3.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: "The `midas` Touch"
author: "Nicholas Jhirad"
params:
version: "0.2.0"
output:
html_document:
keep_md: TRUE
highlight: null
mathjax: null
toc: true
theme: yeti
fold: TRUE
toc_float:
collapsed: FALSE
smooth_scroll: true
---
[![CRAN Status Badge](https://www.r-pkg.org/badges/version/midas)](https://cran.r-project.org/package=midas) [![CRAN Total Downloads](http://cranlogs.r-pkg.org/badges/grand-total/midas)](https://cran.r-project.org/package=midas) [![CRAN Monthly Downloads](http://cranlogs.r-pkg.org/badges/midas)](https://cran.r-project.org/package=midas)
```{r include=FALSE}
local({
hi_pandoc = function(code) {
if (knitr:::pandoc_to() != 'latex') return(code)
if (packageVersion('highr') < '0.6.1') stop('highr >= 0.6.1 is required')
res = highr::hi_latex(code, markup = highr:::cmd_pandoc_latex)
sprintf('\\texttt{%s}', res)
}
hook_inline = knitr::knit_hooks$get('inline')
knitr::knit_hooks$set(inline = function(x) {
if (is.character(x) && inherits(x, 'AsIs')) hi_pandoc(x) else hook_inline(x)
})
})
```
## The midas package
This document covers version >= `r params$version` of the package and is intended to be an
introduction to the package,
The `midas` package turns html code that you can find
around the internet into the necessary shiny functions that
would generate the equivalent shiny objects
## Package Details
The package depends on:
* `xml2` parses html
* `shiny` supports the shiny-object class and the `tag` function
## Why Convert HTML?
Shiny is best when it lets us take what we see elsewhere and reproduce it in a fraction of the time attached to some great data-analysis.
I found myself with the following workflow:
```{r ConvertingHtml, message=FALSE}
# Copy an existing widget or html object
# Either from the web or from an existing function
library(shiny)
library(shinydashboard)
cat(as.character(dashboardHeader()), fill = TRUE)
# Reproduce and Modify
logoHeader <- function(href = '#',
logosrc = 'logo.png',
loadersrc = 'loader.gif',
height='78%',
width='78%',
navbar = NULL) {
tagList(
tags$head(
tags$script(
"setInterval(function(){
if ($('html').attr('class')=='shiny-busy') {
$('div.busy').show();
$('div.notbusy').hide();
} else {
$('div.busy').hide();
$('div.notbusy').show();
}
},100)")
),
tags$header(
class = 'main-header',
tags$span(
class = 'logo',
tags$a(href='#', class = 'logo',
tags$div(
class = 'busy',
tags$img(src = loadersrc,
height = height,
width = width)
),
tags$div(
class = 'notbusy',
tags$img(src = logosrc,
height = height,
width = width)
)
)
),
navbar
)
)
}
```
But for giant pages, this involved a considerable amount of transcription of things like: `<div class="example"></div>` into `tags$div(class="example")`.
I felt that this should be programmatic.
## Converting HTML with midas
Let's try this with midas!
Here's some HTML I found on the internet:
```{r midas_example}
# Let's Try this with midas!
library(midas)
html <-
'<html>
<head>
<style>
#p01 {
color: blue;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p id="p01">I am different.</p>
</body>
</html>'
print(turn_shiny(html))
```