55# '
66# ' @export
77shortenerAddin <- function () {
8-
98 ui <- miniUI :: miniPage(
109 miniUI :: gadgetTitleBar(" Shorten/Expand URL" ),
1110 miniUI :: miniContentPanel(
@@ -25,7 +24,6 @@ shortenerAddin <- function() {
2524 )
2625
2726 server <- function (input , output , session ) {
28-
2927 shortener_provider <- shiny :: reactive({
3028 shiny :: req(input $ provider )
3129 input $ provider
@@ -35,8 +33,10 @@ shortenerAddin <- function() {
3533 output $ bitly_domain <- shiny :: renderUI({
3634 if (shortener_provider() == " bit.ly" ) {
3735 shiny :: tagList(
38- shiny :: textInput(" domain" , label = " Bit.ly domain" , value = " bit.ly" ,
39- width = " 100%" )
36+ shiny :: textInput(" domain" ,
37+ label = " Bit.ly domain" , value = " bit.ly" ,
38+ width = " 100%"
39+ )
4040 )
4141 } else {
4242 return (NULL )
@@ -45,7 +45,6 @@ shortenerAddin <- function() {
4545
4646 # Shorten links
4747 shiny :: observeEvent(input $ shorten , {
48-
4948 shiny :: req(input $ url )
5049
5150 shortener <- get_shortener(provider_name = input $ provider )
@@ -57,24 +56,25 @@ shortenerAddin <- function() {
5756 res <- shortener(longUrl = input $ url )
5857 }
5958
60- tryCatch({
61- parse_response(res ) %> %
62- copy_and_notify()
63- }, error = function (e ) {
64- cli :: cli_alert_danger(e )
65- shiny :: showNotification(
66- ui = paste(" Something went wrong:" , e , sep = " " ),
67- duration = 3L ,
68- closeButton = TRUE ,
69- type = " message"
70- )
71- })
72-
59+ tryCatch(
60+ {
61+ parse_response(res ) %> %
62+ copy_and_notify()
63+ },
64+ error = function (e ) {
65+ cli :: cli_alert_danger(e )
66+ shiny :: showNotification(
67+ ui = paste(" Something went wrong:" , e , sep = " " ),
68+ duration = 3L ,
69+ closeButton = TRUE ,
70+ type = " message"
71+ )
72+ }
73+ )
7374 })
7475
7576 # Expand links
7677 shiny :: observeEvent(input $ expand , {
77-
7878 shiny :: req(input $ url )
7979
8080 expander <- get_expander(provider_name = input $ provider )
@@ -86,26 +86,27 @@ shortenerAddin <- function() {
8686 short_url <- input $ url
8787 }
8888
89- tryCatch({
90- expander(shorturl = short_url ) %> %
91- parse_response(expand = TRUE ) %> %
92- copy_and_notify()
93- }, error = function (e ) {
94- cli :: cli_alert_danger(e )
95- shiny :: showNotification(
96- ui = paste(" Something went wrong:" , e , sep = " " ),
97- duration = 3L ,
98- closeButton = TRUE ,
99- type = " warning"
100- )
101- })
102-
89+ tryCatch(
90+ {
91+ expander(shorturl = short_url ) %> %
92+ parse_response(expand = TRUE ) %> %
93+ copy_and_notify()
94+ },
95+ error = function (e ) {
96+ cli :: cli_alert_danger(e )
97+ shiny :: showNotification(
98+ ui = paste(" Something went wrong:" , e , sep = " " ),
99+ duration = 3L ,
100+ closeButton = TRUE ,
101+ type = " warning"
102+ )
103+ }
104+ )
103105 })
104106
105107 shiny :: observeEvent(input $ done , {
106108 invisible (shiny :: stopApp())
107109 })
108-
109110 }
110111
111112 viewer <- shiny :: dialogViewer(dialogName = " URL shortener" , width = 600 , height = 400 )
@@ -118,14 +119,17 @@ shortenerAddin <- function() {
118119clipShortenerAddin <- function () {
119120 long_url <- clipr :: read_clip()
120121
121- tryCatch({
122- short_url <- bitly_shorten_link(long_url = long_url ) %> %
123- parse_response()
124- clipr :: write_clip(short_url )
125- cli :: cli_alert_success(paste(short_url , " copied to clipboard" , sep = " " ))
126- }, error = function (err ) {
127- cli :: cli_alert_danger(err )
128- })
122+ tryCatch(
123+ {
124+ short_url <- bitly_shorten_link(long_url = long_url ) %> %
125+ parse_response()
126+ clipr :: write_clip(short_url )
127+ cli :: cli_alert_success(paste(short_url , " copied to clipboard" , sep = " " ))
128+ },
129+ error = function (err ) {
130+ cli :: cli_alert_danger(err )
131+ }
132+ )
129133}
130134
131135# ' Expand an URL from clipboard
@@ -135,15 +139,17 @@ clipExpanderAddin <- function() {
135139 bitly_id <- clipr :: read_clip() %> %
136140 gsub(pattern = " https://" , replacement = " " )
137141
138- tryCatch({
139- long_url <- bitly_expand_link(bitlink_id = bitly_id ) %> %
140- parse_response(expand = TRUE )
141- clipr :: write_clip(long_url )
142- cli :: cli_alert_success(paste(long_url , " copied to clipboard" , sep = " " ))
143- }, error = function (e ) {
144- cli :: cli_alert_danger(e )
145- })
146-
142+ tryCatch(
143+ {
144+ long_url <- bitly_expand_link(bitlink_id = bitly_id ) %> %
145+ parse_response(expand = TRUE )
146+ clipr :: write_clip(long_url )
147+ cli :: cli_alert_success(paste(long_url , " copied to clipboard" , sep = " " ))
148+ },
149+ error = function (e ) {
150+ cli :: cli_alert_danger(e )
151+ }
152+ )
147153}
148154
149155
@@ -154,10 +160,10 @@ clipExpanderAddin <- function() {
154160# '
155161# ' @noRd
156162get_shortener <- function (provider_name ) {
157- switch (provider_name ,
158- " bit.ly" = bitly_shorten_link_ ,
159- " is.gd" = isgd_LinksShorten ,
160- " v.gd" = vgd_LinksShorten
163+ switch (provider_name ,
164+ " bit.ly" = bitly_shorten_link_ ,
165+ " is.gd" = isgd_LinksShorten ,
166+ " v.gd" = vgd_LinksShorten
161167 )
162168}
163169
@@ -166,10 +172,10 @@ get_shortener <- function(provider_name) {
166172# ' @inheritParams get_shortener
167173# ' @noRd
168174get_expander <- function (provider_name ) {
169- switch (provider_name ,
170- " bit.ly" = bitly_expand_link_ ,
171- " is.gd" = isgd_LinksExpand ,
172- " v.gd" = vgd_LinksExpand
175+ switch (provider_name ,
176+ " bit.ly" = bitly_expand_link_ ,
177+ " is.gd" = isgd_LinksExpand ,
178+ " v.gd" = vgd_LinksExpand
173179 )
174180}
175181
0 commit comments