Shiny link attachment inside paragraph has unwanted spaces

I am creating a Shiny application with some dynamically generated HTML that includes a link in the middle of the sentence. Unfortunately, if I use tags functions for this, each element has a space around it, whether I want it or not.

For example, if I wanted to write

This is my favorite link ever !

You might think you can do it

 p('This is my ', a(href = 'http://qaru.site/', 'favorite link ever'), '!') 

But this leads to the fact that each element is on a separate line, which according to the HTML specification means that between each space will be displayed.

 <p> This is my <a href="http://qaru.site/">favorite link ever</a> ! </p> 

It looks like this (note the space before the exclamation mark)

This is my favorite link ever !

Do I need to resort to using HTML(paste0(...)) to build my HTML code, or is there some method of using tags functions that I miss?

Thanks..

+9
source share
2 answers

This was solved using a new function, a parameter called .noWS . Quoting Carson Sievert :

Now you can do:

 p('This is my ', a(href = 'https://stackoverflow.com/', 'favorite link ever', .noWS = "outside"), '!', .noWS = c("after-begin", "before-end")) 

which gives

 <p>This is my <a href="https://stackoverflow.com/">favorite link ever</a>!</p> 

Further information on the .noWS parameter can be found in the select query .

0
source

I think you need to use pasta. Otherwise, nesting will not work as expected.

 div(p('hi'),p('what up'),p(HTML(paste0('This is my ',a(href = 'https://stackoverflow.com/', 'favorite link ever'),'!')))) 

Result:

 <div> <p>hi</p> <p>what up</p> <p>This is my <a href="https://stackoverflow.com/">favorite link ever</a>!</p> </div> 

You do not want all of them to be on the same line.

From the help: Named arguments become attributes, and positional arguments become children.

It would be more difficult to have positional arguments, and sometimes not be children; and probably won't be as simple, flexible, and powerful as just creating it.

+2
source

All Articles