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)
Related
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) {}
)
I'm using prettyCheckboxGroup from shinyWidgets within a sidebar panel in Shiny. Some of the items are unavoidably a bit long and so they extend out of the edge of the sidebar.
I'd like to know how to either wrap long text or limit the width for text to force it on to the next line.
I assumed that the width argument would achieve this but it only seems to effect the caption and not the choices text.
The standard checkboxGroupInput did this as standard so I'm wondering if I am missing something with the fancier ShinyWidgets version?
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
sidebarPanel(
width = 2,
uiOutput('boxpick')
)
)
server<- function(input, output) {
output$boxpick <- renderUI(
prettyCheckboxGroup('boxpick', 'Pick an item:',
choices= c('really really long',
'really really really really long',
'really really really really really really really really long')
)
)
}
shinyApp(ui,server)
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.
I am working in a Shiny Flexdashboard and I having a issue with updateSelectInput, and CSS code...
I would like alternatives to solve the issue...
I wanted to lower a table size but I am new in html, CSS and related stuff, so I found the inspiration from here and here (and here specifically mentioned as implemented in flexdashboard) and coded the similar to the following:
selectInput("Indicator","select",choices=c(),selected="NONE")
observe({
Inds<-as.factor(mtcars[,2])%>%levels
updateSelectInput(session,inputId="Indicator",choices=Inds)
})
wellPanel(
div (dataTableOutput ("OrigData"), style = "font-size: 80%"),
dataTableOutput("OrigData"),
)
output$OrigData<-DT::renderDataTable(mtcars)
It makes the lines smaller in the data table rendered as I want, but, the problem is, the selectInput "Indicator" is not updated.
What works: The selectInput "Indicator" is adequately updated if I comment/exclude the line
div (dataTableOutput ("OrigData"), style = "font-size: 80%")
So, I am unable to make they work simultaneously...
The same happens even if I put the select input on the sidebar and the data table in another tab...
There is a kind of incompatibility between the CSS's "div" code and updateSelectInput? What can I do to work with style in flexdashboard (specifically dataTableOutput font-size) without blocking the updateSelectInput?
This is more a workaround, not exactly a solution. But I think it was a good idea to include how I worked around it... It's related to the answer indicated here and uses DT (as described here)
That's not exactly my initial intent, the rownames, title row remain with the original size, but a way to approach partially the issue.
```{r,echo=FALSE}
selectInput("Indicator","select",choices=c(),selected="NONE")
observe({
Inds<-as.factor(mtcars[,2])%>%levels
updateSelectInput(session,inputId="Indicator",choices=Inds)
})
wellPanel(
#div (dataTableOutput ("OrigData"), style = "font-size: 80%"),
dataTableOutput("OrigData"),
)
output$OrigData<-DT::renderDataTable(mtcars%>%
DT::datatable() %>%
DT::formatStyle(columns = colnames(mtcars), fontSize = '50%')
)
```
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"))