Hi, In HTML there is a way to measure the width of a Text before printing it on screen as in https://www.w3schools.com/tags/canvas_measuretext.asp In R we have nchar() function which just measures the number of letters in a Text, but I wonder if we can measure the width of text as well. I have a shiny app where I need to print a text in an Area onto the screen which has a specific width, so some the texts are not showing within that area (overflowing), where some are though all of them have the equal number of letters. Thanks for any input. [[alternative HTML version deleted]]
Hi, Does strwidth() do the trick? https://www.rdocumentation.org/packages/graphics/versions/3.5.1/topics/strwidth <https://www.rdocumentation.org/packages/graphics/versions/3.5.1/topics/strwidth> Ben> On Dec 12, 2018, at 6:55 AM, Christofer Bogaso <bogaso.christofer at gmail.com> wrote: > > Hi, > > In HTML there is a way to measure the width of a Text before printing it on > screen as in https://www.w3schools.com/tags/canvas_measuretext.asp > > In R we have nchar() function which just measures the number of letters in > a Text, but I wonder if we can measure the width of text as well. > > I have a shiny app where I need to print a text in an Area onto the screen > which has a specific width, so some the texts are not showing within that > area (overflowing), where some are though all of them have the equal number > of letters. > > Thanks for any input. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org Ecological Forecasting: https://eco.bigelow.org/ [[alternative HTML version deleted]]
On 12/12/2018 6:55 AM, Christofer Bogaso wrote:> Hi, > > In HTML there is a way to measure the width of a Text before printing it on > screen as in https://www.w3schools.com/tags/canvas_measuretext.asp > > In R we have nchar() function which just measures the number of letters in > a Text, but I wonder if we can measure the width of text as well. > > I have a shiny app where I need to print a text in an Area onto the screen > which has a specific width, so some the texts are not showing within that > area (overflowing), where some are though all of them have the equal number > of letters.Since Shiny displays in a web browser, it will be up to the web browser to measure the text. (How would R know the font, magnification, etc?) You'll have to do this in Javascript. If your R code needs to know the answer, Shiny provides a way to send the result back to R. It's not trivial, but you can read how to do it here: <https://shiny.rstudio.com/articles/js-send-message.html>. Duncan Murdoch> > Thanks for any input. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >