Shiny: Unwanted space before italicized word - r

If you have some experience with the Shiny environment, I would like to ask your help with a little issue. It regards the italicization of text. I have a single italicized word within a normal paragraph, as below:
p(".....blabla (", em("italicized)"), "blabla")
The problem is a space that pops up just before the italicized word, as in: ".....blabla ( italicized)". Would you know how to cancel it?
The problem arises both locally as well as on my shinyapps.io webpage.
N.B. I already asked in the Shiny Google group but there were no answers.
Thank you so much
Further below, I attach an example of the ui.R for reproducibility, to comply with a request. The error is in the third line from the end.
As a disclaimer, though, please note that if remotely this example should have any errors with parentheses or such, the unwanted space I get is with all certainty not due to any of those. The code is altogether smooth besides the unwanted space. I humbly believe this example is not very necessary. The error is only about the unwanted space I get from:
p(".....blabla (", em("italicized)"), "blabla")
library(shiny)
library(ggplot2)
library(leaflet)
library(RCurl)
library(scales)
library(rsconnect)
shinyUI(fluidPage(titlePanel(h3('title',
align = 'center', style = 'color:marengo')),
sidebarLayout(
sidebarPanel(width = 2,
h5(strong('blabla'),
align = 'center'),
selectInput('var1', label = 'blabla',
choices = list('blabla', 'blabla', 'blabla'),
selected = 'blabla'),
selectInput('var2', label = 'blabla',
choices = list('blabla','blabla'),
selected = 'blabla' ),
helpText('blabla')),
mainPanel(
br(),
plotOutput('plot'),
p(".....blabla (", em("italicized)"), "blabla"),
br(),
height = 8, width = 10))))

The function p() might have unwanted side effects. Instead try:
HTML(paste0(".....blabla (", em("italicized)"), "blabla"))

Related

How to divide two words that appear in navigation bar tabs , in shiny app, html?

I am trying to make two lines of the words that appear in each tab, in navigation bar but cannot in any way.
Here it is the pics with the words I am trying to divide in two lines.
And here is a snippet of a code in r script
gene_expressions_sign_tab <- shiny::tabPanel(
"Gene Expression",
icon = icon("chart-line"),
value = "Gene",
wellPanel(
fluidRow("etc")
############################################################################Adding extra info after I have been given an answer bellow
###########################################################################
And it possible to get the two words in two lines in one tab, is it possible to centre the words? the picture reveals the fact the words aren't centered.
Use HTML and embed <br/> in your titles.
library(shiny)
shinyApp(
ui = fluidPage(
tabsetPanel(
tabPanel(HTML("hello<br/>world")),
tabPanel(HTML("hello<br/>again"))
)
),
server = function(input, output, session) {}
)

Aligning the label and radioButton in a fluidRow() in R Shiny

I am trying to align the label and radio button in the same line in the application but I'm unable to achieve that.
This is the code used for displaying the label and radio button
fluidRow(
align = 'center',
column(5,"Choose Metric: "),
column(11, radioButtons("typeRadio", "",list("Project Count", "Project Efforts"), inline = TRUE))
)
But I'm getting this output
How can I get the label and radioButton in the same line?
Can anyone provide a proper solution to achieve the expected output?
It's very hacky, but this works for me:
library(shiny)
ui <- fluidPage(
fluidRow(
align="center",
column(2, "Choose Metric: "),
column(4, radioButtons("typeRadio", "",list("Project Count", "Project Efforts"), inline = TRUE))
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
Your original code defines 16 colulmns. That will cause problems for any solution: the maximum column count is 12.
My solution works because specifying label="" causes Shiny to output the HTML for a label, which is invisible (because it's the empty string), but which still occupies vertical space. Specifying label=NULL suppresses all output associated with the label, and hence it occupies no vertical space.
Put another way, your solution does align the tops of the two widgets. It's just that the top of the radio group is invisible.
Incidentally, it's always best to provide a simple, self-contained example, even for a set up as obvious as this.

Make infobox font size adapt dynamically to content length

I am passing an input selection through to an infobox, using shinydashboard. I am encountering an issue because some of the inputs are short and some are a bit longer. Ideally I want the text to fill the box, but if I set it to the right size for something quite short, then the longer text expands the box in an untidy way. My current approach is therefore to keep the text smaller, but that does mean that when the short input is selected, it is quite diminutive-looking.
I learnt how to change text size with this answer. However, this sets the size in a way that doesn't respond to different inputs - so presumably the percentage relates to the default size rather than to the box dimensions.
Possibly CSS? Simply because so much styling goes that way - but I'm not very proficient here. Or possibly some sort of if statement, or using conditionalPanel or validate - but I'm not sure what the logic would be? I have tried without any luck on those (and my attempts have been quite bulky anyway).
Example code (with text on the larger size):
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
selectInput(
"text_select", label = "Please select",
choices = c("Short", "A longer option to choose")
)
)
body <- dashboardBody(
fluidRow(infoBoxOutput("selected")
)
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
output$selected<- renderInfoBox({
infoBox(title = "Selected",
value = tags$p(input$text_select,
style = "font-size: 190%;"),
icon = icon("bullseye"), color = "red")
})
}
shinyApp(ui, server)

How can I put multiple plots side-by-side in a tab panel with other outputs present, shiny r?

This question is a follow-up to How can put multiple plots side-by-side in shiny r? and R Shiny layout - side by side chart and/or table within a tab.
Is it possible to embed two side-by-side plots in a tab panel when there are other outputs present besides the two plots I want to embed side-by-side? I have tried every suggestion offered in the answers to the previous two questions and nothing works. No matter what I try I end up breaking my program so it refuses to display any out put at all.
mainPanel(
width = 10,
tabsetPanel(
tabPanel("Dashboard", textOutput("text30"), textOutput("text31"), textOutput("text28"), textOutput("text29"),
column(6, plotOutput("plot1st"), column(6, plotOutput("plot2nd")), #what do I put here to make this work?
plotOutput("plot3rd"), plotOutput("plot9th"), plotOutput("plot4th"), plotOutput("plot8th"), plotOutput("plot7th"), plotOutput("plot6th")),
tabPanel("Graph Switcher", plotOutput("selected_graph"))
))))
Is there anything I can do to make this work?
Update: Thanks to Florian's answer I was able to make the app look the way I wanted. However, as can be seen in the screenshot below, a small number 12 appears in between the plots, and the plots are not perfectly horizontally aligned. I'm wondering if it's possible to fix this?
You can put multiple column elements in one fluidRow:
Hope this helps!
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("Dashboard",
fluidRow(12,
column(6,plotOutput('plot1')),
column(6,plotOutput('plot2'))
),
fluidRow(12,
column(4,plotOutput('plot3')),
column(4,plotOutput('plot4')),
column(4,plotOutput('plot5'))
),
fluidRow(12,
column(3,plotOutput('plot6')),
column(3,plotOutput('plot7')),
column(3,plotOutput('plot8')),
column(3,plotOutput('plot9'))
)
)))
server <- function(input,output)
{
lapply(seq(10),function(x)
{
output[[paste0('plot',x)]] = renderPlot({hist(runif(1:20))})
})
}
shinyApp(ui,server)

R Shiny tabBox title break

I am having a slight issue with R Shiny dashboards that I hope someone might be able to help me with.
Below is an extract for one of the shiny apps I am working on. On this page there are two panels on the same row side by side, and each panel has two tabs in it, each with their own graph. Each panel has a consistent title, with a slightly different bit in brackets. I have noticed that when I resize the browser window (although R shiny is very good and dynamically changes the plot, text etc to fit the new size) the slightly longer title jumps to the row below the tabPanel() choices before the shorter title. This causes the two panels to be of differing height in the row and makes it look a bit untidy.
Therefore, is there a way to split the panel title over multiple lines? I have searched for this for a while, and have tried "\n", "\r\n", "|" etc with no luck. Alternatively, if there is another solution to this I would be very happy to hear it.
Thank you for the help, and apologies if the answer is out there and I have just missed it!
fluidRow(
tabBox(
title = "Consistent Title (bit in brackets)",
side = "right",
tabPanel(
"Panel title X",
textOutput("X_total"),
plotOutput("X"),
tags$i("All metrics calculated based on blah.")
),
tabPanel(
"Panel title Y",
textOutput("Y_mean"),
plotOutput("Y"),
tags$i("All metrics calculated based on blah.")
), width = 6),
tabBox(
title = "Consistent Title (longer bit in brackets)",
side = "right",
tabPanel(
"Panel title A",
textOutput("A_total"),
plotOutput("A"),
tags$i("All metrics calculated based on blah.")
),
tabPanel(
"Panel title B",
textOutput("B_total"),
plotOutput("B"),
tags$i("All metrics calculated based on blah.")
), width = 6)
)
A bit of searching led to the following page:
how to insert new line in R shiny string
And therein lies the answer. In the code provided in the question we need to put the following as the title function:
title = HTML(paste("Consistent title", "(bit in brackets)", sep = "<br/>"))

Resources