I wish to center a small form below a table that is also centered.
I center the table using, fluidRow and column like so:
fluidRow(
column(12, align="center", reactableOutput("table")),
),
If I do the same with the form, each component of the form becomes centered in the page which is wrong. How do I center a correct looking form beneath the centered table?
Example Code
library(shiny)
library(reactable)
ui <- fluidPage(
fluidRow(
column(12, align="center", reactableOutput("table")),
),
fluidRow(
column(12,
div(id = "form",
textInput("email", "Email", width = "250px", placeholder = "joe#example.com"),
radioButtons(inputId = "pref",
label ="Here's a label:",
choiceNames = list(
"First choice",
"Second choice"),
choiceValues = list(
"v1", "v2"
)),
actionButton("submit", "Enter", class = "btn-primary", width = 250,
style="color: #FFF; background-color: #132EBA;"),
)
)
)
)
server <- function(input, output, session) {
output$table <- renderReactable({
reactable(iris,
fullWidth = FALSE)
})
observeEvent(input$submit, {
# Do something!
})
}
shinyApp(ui, server)
You need to create 2 div elements and give them CSS properties :
first one is centered
second one is an inline-block and aligned left
Source : CSS: Center block, but align contents to the left
So it gives
library(shiny)
library(reactable)
ui <- fluidPage(
fluidRow(
column(12, align="center", reactableOutput("table")),
),
fluidRow(
column(12,
div(id = "form",
style = "text-align: center;",
div(
id = "form_content",
style = "display:inline-block; text-align: left;",
textInput("email", "Email", width = "250px", placeholder = "joe#example.com"),
radioButtons(inputId = "pref",
label ="Here's a label:",
choiceNames = list(
"First choice",
"Second choice"),
choiceValues = list(
"v1", "v2"
)),
actionButton("submit", "Enter", class = "btn-primary", width = 250,
style="color: #FFF; background-color: #132EBA;")
)
)
)
)
)
server <- function(input, output, session) {
output$table <- renderReactable({
reactable(iris,
fullWidth = FALSE)
})
observeEvent(input$submit, {
# Do something!
})
}
shinyApp(ui, server)
Related
I am trying to center-align tabsetpanel "pills" on shiny, but it alwais get on left position. Here is the code example, anyone knows how to align this buttons or pills center?
library(shiny)
ui <- fluidPage(
tabPanel(title = "Hello world", value = "HB",
tabsetPanel(id="subtabs", type="pills",
tabPanel(title = "TAB 1", value = "ILPF",
br(),
h4("I like Pink floyd, my favourite album is 'The dark side of the moon'", style = "color:grey", align = "center"),
br()
),
tabPanel(title = "TAB 2", value = "FS",
br(),
h4("But my favourite song is 'Shine on you crazy diamond'", style = "color:grey", align = "center"),
br()
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
The pills should be in the middle of the page
You can do so by adding some CSS to your app. tags$style('ul.nav-pills{display: flex !important;justify-content: center !important;}') does the trick.
library(shiny)
ui <- fluidPage(
tags$head(
tags$style('
ul.nav-pills{
display: flex !important;
justify-content: center !important;
}')
),
tabPanel(title = "Hello world", value = "HB",
tabsetPanel(id="subtabs", type="pills",
tabPanel(title = "TAB 1", value = "ILPF",
br(),
h4("I like Pink floyd, my favourite album is 'The dark side of the moon'", style = "color:grey", align = "center"),
br()
),
tabPanel(title = "TAB 2", value = "FS",
br(),
h4("But my favourite song is 'Shine on you crazy diamond'", style = "color:grey", align = "center"),
br()
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
The reproducible code below uses a fluidRow() to house several user selections using radio buttons. Works fine in this limited example of only 2 radio button groupings. But I need to fit more radio button groupings into this row, without any wrapping. To do this, I'd like to replace this combination of fluidRow()/column() with a horizontally scrollable, non-wrapping row that is not subject to the limitations of the 12-wide grid system currently used in this code.
Also, all objects viewed in the scrolling row need to be left aligned without "fluid" expansion. Currently, using this fluidRow()/column() combo, if the viewing pane is expanded, the 2 columns housing each radio button grouping also expanded which doesn't look good. They need to remain fixed width and stay to the left.
Is this possible?
I prefer sticking with this sidebar/main panel/tab panel/conditional panel layout as I find it very user friendly for navigating the type of data we work with.
The image at the bottom further explains.
Reproducible code:
library(dplyr)
library(DT)
library(shiny)
library(shinyWidgets)
ui <-
fluidPage(
titlePanel("Summary"),
sidebarLayout(
sidebarPanel(
selectInput("selectData", h5("Select data to view:"),
choices = list("Beta"),
selected = "Beta"),
),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
conditionalPanel(condition = "input.selectData == 'Beta'",
fluidRow(div(style = "margin-top:15px"),
column(width = 6, offset = 0,
wellPanel(
radioButtons(inputId = 'group1',
label = NULL,
choiceNames = c('By period','By MOA'),
choiceValues = c('Period','MOA'),
selected = 'Period',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
),
column(width = 6, offset = 0,
wellPanel(
radioButtons(inputId = 'group2',
label = NULL,
choiceNames = c('Exclude CT','Include CT'),
choiceValues = c('Exclude','Include'),
selected = 'Exclude',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
)
),
DTOutput("plants")
)
),
id = "tabselected"
)
)
)
)
server <- function(input, output, session) {
output$plants <- renderDT({iris %>% datatable(rownames = FALSE)})
}
shinyApp(ui, server)
How about using a carousel instead e.g. via shinyglide or slickR:
library(dplyr)
library(DT)
library(shiny)
library(shinyWidgets)
library(shinyglide)
ui <-
fluidPage(
titlePanel("Summary"),
sidebarLayout(
sidebarPanel(
selectInput("selectData", h5("Select data to view:"),
choices = list("Beta"),
selected = "Beta"),
),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
conditionalPanel(condition = "input.selectData == 'Beta'",
fluidRow(div(style = "margin-top:15px"),
column(12, glide(
height = "25",
controls_position = "top",
screen(
p(strong("Group 1")),
wellPanel(
radioButtons(inputId = 'group1',
label = NULL,
choiceNames = c('By period','By MOA'),
choiceValues = c('Period','MOA'),
selected = 'Period',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
),
screen(
p(strong("Group 2")),
wellPanel(
radioButtons(inputId = 'group2',
label = NULL,
choiceNames = c('Exclude CT','Include CT'),
choiceValues = c('Exclude','Include'),
selected = 'Exclude',
inline = TRUE
),
style = "padding-top: 12px; padding-bottom: 0px;"
)
)
))
),
DTOutput("plants")
)
),
id = "tabselected"
)
)
)
)
server <- function(input, output, session) {
output$plants <- renderDT({iris %>% datatable(rownames = FALSE)})
}
shinyApp(ui, server)
Any guidance please on how to arrange the buttons in the app below into a neat straight line while still inheriting the ‘center’ alignment from the column? I am looking to keep the column’s ‘centre’ alignment so that the buttons line up under the “Center Aligned Title”, however this then lines up each choice in an erratic manner, dependent on the length of the choice.
library(shiny)
app <- shinyApp(
ui = fluidPage(
column(4),
column(4,
fluidRow(
column(12,
align = 'center',
h6('Center Aligned Title')
)
),
fluidRow(
column(12,
align = 'center',
# align = 'left', # This justifies/arranges the buttons neatly
# but not underneath "Center Aligned Title"
radioButtons(
inputId = 'my_btns',
label = NULL,
choices = c('abc','defg','hijllm','no'),
selected = character(0),
inline = F
)
)
)
),
column(4)
),
server = function(input, output) {}
)
runApp(app)
You could drop align = 'center' in the second column() and use CSS to align the radio buttons in a flexbox like this:
app <- shinyApp(
ui = fluidPage(
tags$head(
tags$style(HTML("
#my_btns, #my_div {
display: flex;
justify-content: center;
}"
))
),
fluidRow(
column(12,
align = 'center',
h6('Center Aligned Title')
)
),
fluidRow(
column(12,
div(
radioButtons(
inputId = 'my_btns',
label = NULL,
choices = c('abc','defg','hijllm','no'),
selected = character(0),
inline = F
), id = "my_div")
)
)
),
server = function(input, output) {}
)
Result:
How do I adjust the spacing between the end of the table and the sentence, "Place very close to table".
Here is the default spacing:
Here is the desired spacing:
R Script
library("shiny")
library("shinydashboard")
shinyApp(
ui = dashboardPage(
dashboardHeader(disable = TRUE),
dashboardSidebar(width = 0),
body <- dashboardBody(
fluidRow(
tabBox(
id = "tabset1", height = "250px",
tabPanel("Tab1", "First tab content"),
tabPanel("Tab2", "Tab content 2")
),
),
fluidRow(htmlOutput("last_updated"))
)
),
server = function(input, output) {
# The currently selected tab from the first box
output$tabset1Selected <- renderText({
input$tabset1
})
output$last_updated <- renderText({
paste("<font size='1px;'> Place very close to table</font>")
})
}
)
A possibility:
body <- dashboardBody(
div(
style = "display: flex; flex-direction: column;",
tabBox(
id = "tabset1", height = "250px",
tabPanel("Tab1", "First tab content"),
tabPanel("Tab2", "Tab content 2")
),
div(style = "margin-top: -20px;"),
htmlOutput("last_updated")
)
)
I want to change the name of the photo in front of the photo by changing each photo from the slide.
But using the following codes, the input id is not displayed at all. The codes are as follow
library(shinydashboardPlus)
ui<- dashboardPagePlus(title="Sample",
dashboardHeaderPlus(title="Sample"),
dashboardSidebar(),
dashboardBody(
fluidRow(column(width=6,
carousel(
id = "AA",
carouselItem(
caption = "Image1",
tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
),
carouselItem(
caption = "Image2",
tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
))),
column(width=6, uiOutput("Text"))
)
)
)
server<- function(input, output, session) {
output$Text<-renderText({
Text<-input$AA
as.character(Text)
})
}
shinyApp(ui, server) ```
I do see them showing up. It's easier to see if you change the font size and color:
library(shinydashboardPlus)
library(shinydashboard)
ui<- dashboardPagePlus(title="Sample",
dashboardHeaderPlus(title="Sample"),
dashboardSidebar(),
dashboardBody(
htmltools::tags$style(
".carousel-caption{
font-size: 48px;
color: black;
}"
),
fluidRow(column(width=6,
carousel(
id = "AA",
carouselItem(
caption = "Image1",
tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
),
carouselItem(
caption = "Image2",
tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
))),
column(width=6, uiOutput("Text"))
)
)
)
server<- function(input, output, session) {
output$Text<-renderText({
Text<-input$AA
as.character(Text)
})
}
shinyApp(ui, server)
As you are using uiOutput, try renderUI on the server side. Also, to show different text in each image, you need to define renderText and output it in carouselItem. Try this code
library(shinydashboardPlus)
library(shinydashboard)
ui<- dashboardPagePlus(title="Sample",
dashboardHeaderPlus(title="Sample"),
dashboardSidebar(),
dashboardBody(
tags$head(
tags$style(HTML("
#AA{
width:900px;
height:600px;
}
.carousel-control{
color:#FF0000;
}
.carousel-caption{
font-size: 48px;
color: red;}
"))
),
fluidRow(column(width=6,
carousel(
id = "AA",
carouselItem(
caption = "Image1",
textOutput("text1"),
tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
),
carouselItem(
caption = "Image2",
textOutput("text2"),
tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
))),
column(width=6, uiOutput("Text"))
)
)
)
server<- function(input, output, session) {
output$Text<-renderUI({
#Text<-as.character(input$AA)
tagList(
p("I like to print something over all images", style = "color:blue")
)
})
output$text1 <- renderText("Print something in image 1")
output$text2 <- renderText("Print something in image 2")
}
shinyApp(ui, server)