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.
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 currently building a shiny app to build biological networks. To build them, you can choose between many different parameters, which i included in different selectInputs or numericInputs.
Is it possible to have some kind of info text, when hovering the mouse over those input fields? I dont want to add 3-4 sentences of text to the title of each select/numericInput.
Thanks :)
If you don't mind an extra package dependancy then you can use bsTooltip from the shinyBS package. Note that the hover tooltip sometimes doesn't show up unless you click on the input in the RStudio viewer pane, but if you run your app in your browser, the hover trigger should work:
library(shiny)
library(shinyBS)
ui <- fluidPage(
selectInput("input1", "Select input", c("choice1", "choice2")),
bsTooltip(id = "input1",
title = "Here is some text with your instructions")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
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)
I've got a Flexdashboard-based Shiny application with several tabs, and within each tab, grids of multiple plots. Performance is a bit of an issue, particularly when deployed on the free Shiny Server.
Initially, the main issue was that clicking each tab would require re-rendering of the plots. I set the suspendWhenHidden option to be FALSE, and this helps - Now switching the input has a slow delay to load all the plots, but at least when navigating the UI, performance is snappy.
This got me thinking, however - is there any way to achieve a hybrid of the two behaviors? So say I'm on an active tab which just produces a single plot. This plot renders quickly. Can we tell shiny to render this plot, display it to the user, and then in the background, continue loading all the elements of the other tabs? As it stands now, the active tab will not finish rendering the plot until all plots on the hidden tabs are also rendered.
In summary, a hybrid suspendWhenHidden = FALSE and TRUE:
Render the active tab elements first, display to the user, then
Continue rendering the elements on the hidden tabs
I thought perhaps setting priority might achieve this, but it doesn't seem to work. Any thoughts or suggestions?
Here's a minimal reproducible example. The goal would be for the first plot (in tab 1) to render and appear before beginning rendering of the second plot (in tab 2) - But the plot should start rendering in tab 2 without requiring a click of tab 2.
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput('n', 'Size', 10)
),
mainPanel(
tabsetPanel(
tabPanel("Tab1", plotOutput("plot1")),
tabPanel("Tab2", plotOutput("plot2"))))
)
)
# Define the server code
server <- shinyServer(function(input, output, session) {
output$plot1 <- renderPlot({plot(1:input$n)},height = 400,width=800)
output$plot2 <- renderPlot({ Sys.sleep(5); plot(1:input$n,col="red")},height = 400,width=800)
outputOptions(output, "plot2", suspendWhenHidden = FALSE)
})
# Return a Shiny app object
shinyApp(ui = ui, server = server)
There is two ways to achieve this
Load all the tabs and then show the output
Use eventReactive to activate the other tabs
For the first option just put below additionally
outputOptions(output, "plot1", suspendWhenHidden = FALSE)
and if you want reactivity write eventReactive functions for each tab.