-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathshiny.Rmd
165 lines (124 loc) · 3.46 KB
/
shiny.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
title: Shiny Examples
author: Joshua Kunst
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
description: >
This article show how simple is integrate highcharter widgets into your shiny
apps. Here you will find some specific examples like the use of proxy funcions
and other apps to give you some inspiration.
editor_options:
chunk_output_type: console
vignette: >
%\VignetteIndexEntry{Shiny Examples}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
<script>
$(document).ready(function(){
el = $(".page-header > h1")
icon = "magic"
text = el.text()
text_new = "<span class=\"fa fa-" + icon + "\"></span> " + text
el.html(text_new)
}) ;
</script>
```{r, include=FALSE}
library(highcharter)
options(highcharter.theme = hc_theme_hcrt(tooltip = list(valueDecimals = 2)))
knitr::opts_chunk$set(eval = FALSE)
```
Let's check some examples!
```{r, include=FALSE}
knitr::opts_chunk$set(fig.align = "center")
library(tidyverse)
library(rvest)
doc <- rvest::read_html("https://github.com/jbkunst/highcharter-shiny")
apps <- doc |>
html_nodes(".js-navigation-open") |>
html_attr("title") |>
na.omit() |>
as.character() |>
str_subset("^[0-9]{2}")
apps
library(furrr)
# plan(multisession, workers = 10)
# dinfo <- future_map_dfr(apps, function(x = "03-events-v2"){
dinfo <- map_df(apps, function(x = "05-arma"){
message(x)
app_url <- str_glue("http://jbkunst.shinyapps.io/", x)
src_url <- str_glue("https://github.com/jbkunst/highcharter-shiny/tree/master/", x)
description <- str_glue(
"https://raw.githubusercontent.com/jbkunst/highcharter-shiny/master/{ folder }/DESCRIPTION",
folder = x
)
status <- httr::status_code(httr::GET(description))
tmp <- tempfile()
if(status == 404) {
writeLines("", con = tmp)
description <- desc::description$new(file = tmp)
} else {
download.file(description, tmp)
description <- desc::desc(tmp)
}
readme.dm <- str_glue(
"https://raw.githubusercontent.com/jbkunst/highcharter-shiny/master/{ folder }/Readme.md",
folder = x
)
status <- httr::status_code(httr::GET(readme.dm))
if(status == 404) {
readme.dm <- ""
} else {
readme.dm <- readLines(readme.dm)
}
img_tmp <- tempfile(fileext = ".png")
img_tmp |> str_replace_all("\\\\", "/")
shot <- webshot2::webshot(
app_url,
file = img_tmp,
delay = 15,
zoom = 0.5,
vwidth = 1336,
vheight = 768,
cliprect = "viewport"
)
img_uri <- knitr::image_uri(img_tmp)
dout <- tibble(
app = x,
title = coalesce(description$get("Title"), x),
url = app_url,
src = src_url,
shot = img_uri,
text = list(readme.dm)
)
# dout <- mutate(dout, across(everything(), as.character))
dout
})
dinfo <- left_join(
dinfo,
tibble(app = apps) |> mutate(id = dplyr::row_number()),
by = "app"
) |>
arrange(id) |>
select(-id, -app)
dinfo
```
```{r, results='asis', echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
pwalk(dinfo, function(title, url, src, shot, text){
cat("\n")
cat(str_c("## ", title, "\n"))
cat(str_c("* Live: ", url, "\n"))
cat(str_c("* Code: ", src, "\n"))
cat("\n")
# cat("<img src='", shot, "'/>\n")
htmltools::tags$img(src = shot) |>
htmltools::a(href = url, target = "_blank") |>
as.character() |>
cat("\n")
htmltools::tags$br() |>
as.character() |>
cat("\n")
cat(str_c(text, "\n"))
cat("\n")
})
```