-
Notifications
You must be signed in to change notification settings - Fork 4
/
tutorial4.R
174 lines (160 loc) · 3.78 KB
/
tutorial4.R
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
library(htmltools)
library(pipeR)
tagList(
tags$div(
id = "content"
)
,tags$script(type = "text/babel"
,'
// tutorial3.js
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm />
</div>
);
}
});
// tutorial4.js
var CommentList = React.createClass({
render: function() {
return (
<div className="commentList">
<Comment author="Pete Hunt">This is one comment</Comment>
<Comment author="Jordan Walke">This is *another* comment</Comment>
</div>
);
}
});
var CommentForm = React.createClass({
render: function() {
return (
<div className="commentForm">
Hello, world! I am a CommentForm.
</div>
);
}
});
// tutorial5.js
var Comment = React.createClass({
render: function() {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
{this.props.children}
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById("content")
);
' %>>% HTML
)
) %>>%
attachDependencies(list(
htmlDependency(
name = "react"
,version = "0.14.8"
,src = c(paste0(getwd(),"/build"))
,script = c("react.min.js","react-dom.min.js")
)
,htmlDependency(
name = "babel-browser"
,version = "5.8.23"
,src = c(href="http://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23")
,script = c("browser.min.js")
)
,htmlDependency(
name = "jquery"
,version = "2.2.0"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/")
,script = c("jquery.min.js")
)
,htmlDependency(
name = "marked"
,version = "0.3.5"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/")
,script = c("marked.min.js")
)
)) %>>%
html_print
# use reactR --------------------------------------------------------------
library(htmltools)
library(reactR)
tagList(
tags$div(id = "content"),
tags$script(babel_transform(
'// tutorial3.js
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm />
</div>
);
}
});
// tutorial4.js
var CommentList = React.createClass({
render: function() {
return (
<div className="commentList">
<Comment author="Pete Hunt">This is one comment</Comment>
<Comment author="Jordan Walke">This is *another* comment</Comment>
</div>
);
}
});
var CommentForm = React.createClass({
render: function() {
return (
<div className="commentForm">
Hello, world! I am a CommentForm.
</div>
);
}
});
// tutorial5.js
var Comment = React.createClass({
render: function() {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
{this.props.children}
</div>
);
}
});
ReactDOM.render(
<CommentBox />,
document.getElementById("content")
);'
))
) %>>%
attachDependencies(list(
html_dependency_react(),
htmlDependency(
name = "jquery"
,version = "2.2.0"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/")
,script = c("jquery.min.js")
),
htmlDependency(
name = "marked"
,version = "0.3.5"
,src = c(href = "http://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/")
,script = c("marked.min.js")
)
)) %>>%
browsable()