selectizeInput() box slightly taller than rest - r

I ran into a bit of trouble in my app. I have a fluidrow, which contains 2 colums, and these columns again contain fluid rows.
I have a textinput in the left column and a selectInput (with selectize = TRUE) on the right side.
While the contents of that row are on exactly one level, the contents of the next row are sadly pushed further down. This only happens with a selectInput in that location, so I assume that it has a larger margin below than for example a textInput.
I hope somebody had a similar problem an a solution before!
edit:
fluidRow(
column(
width = 4,
offset = 2,
h3("Unsere Kontaktdaten"),
fluidRow(
column(
width = 12,
disabled(
textInput(
inputId = "Kontakt",
label = "Firma",
value = "Digitale Giganten",
width = "100%"
)
),
)
),
fluidRow(
column(
width = 9,
disabled(
textInput(
inputId = "unsere_straße",
label = "Straße",
value = "Mohnstraße",
width = "100%"
)
),
),
column(
width = 3,
disabled(
textInput(
inputId = "unsere_hausnummer",
label = "Hausnummer",
value = 123,
width = "100%"
)
),
)
),
),
column(
width = 4,
offset = 1,
h3("Ansprechpartner"),
fluidRow(
column(
width = 3,
disabled(
selectInput(
inputId = "unsere_anrede",
label = "Anrede",
choices = c("Herr", "Frau", "Divers"),
width = "100%" )
)
),
column(
width = 9,
disabled(
textInput(
inputId = "unser_ansprechpartner",
label = "Ansprechpartner",
width = "100%",
value = "name"
)
)
)
),
disabled(
textInput(
inputId = "unsere_nummer",
label = "Telefon",
width = "100%",
value = 123456789
)
),
)
),

You can fix this via css. I wrapped the selectinput in a div() to style it:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
width = 4,
offset = 2,
h3("Unsere Kontaktdaten"),
fluidRow(
column(
width = 12,
disabled(
textInput(
inputId = "Kontakt",
label = "Firma",
value = "Digitale Giganten",
width = "100%"
)
),
)
),
fluidRow(
column(
width = 9,
disabled(
textInput(
inputId = "unsere_straße",
label = "Straße",
value = "Mohnstraße",
width = "100%"
)
),
),
column(
width = 3,
disabled(
textInput(
inputId = "unsere_hausnummer",
label = "Hausnummer",
value = 123,
width = "100%"
)
),
)
),
),
column(
width = 4,
offset = 1,
h3("Ansprechpartner"),
fluidRow(
column(
width = 3,
disabled(
div(selectInput(
inputId = "unsere_anrede",
label = "Anrede",
choices = c("Herr", "Frau", "Divers"),
width = "100%"),
style = "margin-bottom: -5px;")
)
),
column(
width = 9,
disabled(
textInput(
inputId = "unser_ansprechpartner",
label = "Ansprechpartner",
width = "100%",
value = "name"
)
)
)
),
disabled(
textInput(
inputId = "unsere_nummer",
label = "Telefon",
width = "100%",
value = 123456789
)
),
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
If you have multiple selectInputs you need to style and don't want to wrap each in a div, you can add:
tags$style("
.selectize-input {
margin-bottom: -5px !important;
}
")
somewhere in your UI.

Related

How to make bs4Dash Box within Box appear inline and with equal widths

Using bs4Dash, I am trying to create a box that contains several other boxes, have them horizontally aligned, and span equal-distances across the page no matter how big or small the window is. I was able to get the boxes in-line using a div(), but cannot seem to make them equidistant in width.
This is my reproducible example:
if (interactive()) {
library(shiny)
library(bs4Dash)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(width = 12, div(style="display: inline-block;vertical-align:top;", box(
solidHeader = FALSE,
title = "Status summary",
background = NULL,
width = 12,
status = "danger",
footer = fluidRow(
descriptionBlock(
number = "17%",
numberColor = "pink",
numberIcon = icon("caret-up"),
header = "$35,210.43",
text = "TOTAL REVENUE",
rightBorder = TRUE,
marginBottom = FALSE
),
descriptionBlock(
number = "18%",
numberColor = "secondary",
numberIcon = icon("caret-down"),
header = "1200",
text = "GOAL COMPLETION",
rightBorder = FALSE,
marginBottom = FALSE
)
)
)),
div(style="display: inline-block;vertical-align:top;", box(title = "second box", width = 12))
)
)
),
title = "Description Blocks"
),
server = function(input, output) { }
)
}
I'm not sure if you've answered this question since you posted it, but it might be useful for others.
In bs4Dash, the key is to use constant combinations of fluidRow(column(width = X, box(width = NULL))) even within boxes.
For example, a box with two boxes inside of it might look like this:
column(width = 12,
box(width = NULL, title = "Main box",
fluidRow(
column(width = 6,
box(width = NULL, title = "Internal box 1")
),
column(width = 6,
box(width = NULL, title = "Internal box 2")
)
)
)
)
Here's a reproducible example that should achieve your outcomes:
library(shiny)
library(bs4Dash)
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidRow(
column(width = 12,
box(width = NULL,
fluidRow(
column(width = 6,
box(
solidHeader = FALSE,
title = "Status summary",
background = NULL,
width = NULL,
status = "danger",
footer = fluidRow(
column(width = 6,
descriptionBlock(
number = "17%",
numberColor = "pink",
numberIcon = icon("caret-up"),
header = "$35,210.43",
text = "TOTAL REVENUE",
rightBorder = TRUE,
marginBottom = FALSE
)
),
column(width = 6,
descriptionBlock(
number = "18%",
numberColor = "secondary",
numberIcon = icon("caret-down"),
header = "1200",
text = "GOAL COMPLETION",
rightBorder = FALSE,
marginBottom = FALSE
)
)
)
)
),
column(width = 6,
box(title = "second box", width = NULL))
)
)
)
)
)
)
server = function(input, output) { }
shinyApp(ui = ui, server = server)

shinjs::show() not showing element after shinyjs::hide()

I have a shiny dashboard where I'm trying to use action buttons to select through what to show instead of the menu tabs. I have it built so that when you click the action button assigned to one specific fluid row it will hide the other tabs, but I can't seem to get it to bring the fluid row back. I'm using shinyjs show and hide functions.
this is the code I have in my ui
dashboardBody(
tags$head(
tags$link(
rel = "stylesheet",
type = "text/css",
href = "datainstate_style.css")
),
useShinyjs(),
introjsUI(),
# MAIN BODY ----------------------------------------------------------------
fluidRow(
column(
width = 12,
bsButton("VsOpponent",
label = "Vs Opponent",
icon = icon("users"),
style = "success"),
bsButton("trendsinperformance",
label = "Trends",
icon = icon("digital-tachograph"),
style = "success"),
bsButton("lineupsandchampions",
label = "Lineups and Champions",
icon = icon("child"),
style = "success")
)
),
fluidRow(
div( id = "VsOpponent_panel",
column(
width = 12,
gt_output("opponents_table")
),
column(
width = 12,
plotOutput("radar_plot")
),
column(
width = 12,
plotOutput("gold_plot")
)
)
),
fluidRow(
div( id = "trendsinperformance_panel",
column(
width = 12,
plotOutput("gold")
)
)
),
fluidRow(
div( id = "lineupsandchampions_panel",
column(
width = 12,
textOutput("test")
)
)
)
)
And then the code in my server that corresponds to this is below
## Determine which panel to show
observeEvent("", {
show("VsOpponent_panel")
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
}, once = TRUE)
observeEvent(input$VsOpponent, {
show("VsOpponent_panel")
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
})
observeEvent(input$trendsinperformance, {
show("trendsinperformance_panel")
hide("lineupsandchampions_panel")
hide("VsOpponent_panel")
})
observeEvent(input$lineupsandchampions, {
show("lineupsandchampions_panel")
hide("trendsinperformance_panel")
hide("VsOpponent_panel")
})
Thanks for your help!
Hmm, the buttons seem to work for me as expected, try to hide the divs first then show the other ones
library(shiny)
library(shinyjs)
library(shinyBS)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
width = 4,
bsButton("VsOpponent",
label = "Vs Opponent",
icon = icon("users"),
style = "success"),
bsButton("trendsinperformance",
label = "Trends",
icon = icon("digital-tachograph"),
style = "success"),
bsButton("lineupsandchampions",
label = "Lineups and Champions",
icon = icon("child"),
style = "success")
)
),
fluidRow(
div(id = "VsOpponent_panel",
column(
width = 4,
plotOutput("p1")
),
column(
width = 4,
plotOutput("p2")
),
column(
width = 4,
plotOutput("p3")
)
)
),
fluidRow(
div( id = "trendsinperformance_panel",
column(
width = 4,
plotOutput("p4")
)
)
),
fluidRow(
div( id = "lineupsandchampions_panel",
column(
width = 4,
plotOutput("p5")
)
)
)
)
server <- function(input, output, session) {
output$p1 <- renderPlot({plot(runif(10),main = "Plot1")})
output$p2 <- renderPlot({plot(runif(10),main = "Plot2")})
output$p3 <- renderPlot({plot(runif(10),main = "Plot3")})
output$p4 <- renderPlot({plot(runif(10),main = "Plot4")})
output$p5 <- renderPlot({plot(runif(10),main = "Plot5")})
## Determine which panel to show
observeEvent("", {
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
show("VsOpponent_panel")
}, once = TRUE)
observeEvent(input$VsOpponent, {
hide("lineupsandchampions_panel")
hide("trendsinperformance_panel")
show("VsOpponent_panel")
})
observeEvent(input$trendsinperformance, {
hide("lineupsandchampions_panel")
hide("VsOpponent_panel")
show("trendsinperformance_panel")
})
observeEvent(input$lineupsandchampions, {
hide("trendsinperformance_panel")
hide("VsOpponent_panel")
show("lineupsandchampions_panel")
})
}
shinyApp(ui, server)

R Shiny ValueBox and Table layout

I am building one UI in R Shiny and struggling with the layout part. I want to plot ValueBoxes and Table together. Following is the current output but, the rows are coming with the gap. So, could you suggest what can be done to remove this gap and get the desired layout. Here is the code
tabItem("overall_current_performance",
fluidRow(
column(width = 12,
valueBoxOutput("vlue", width = 3),
valueBoxOutput("vlue1", width = 3),
valueBoxOutput("win_loose", width = 3),
box(
title = "Box title", width = 3,
div(style = "height:200px"), status = "primary",
"Box content"
)
),
column(width = 12,
valueBoxOutput("performance", width = 3),
valueBoxOutput("performance1", width = 3),
valueBoxOutput("win_loose1", width = 3)
)
)
)
Current Layout with row gap:
Following changes gives correct layout,
column(
width = 3,
valueBoxOutput(
"vlue", width = NULL
),
valueBoxOutput(
"vlue1", width = NULL
)
),
column(width = 3,
valueBoxOutput(
"performance", width = NULL
),
valueBoxOutput(
"performance1", width = NULL
)
),
column(width = 3,
valueBoxOutput(
"win_loose", width = NULL
),
valueBoxOutput(
"win_loose1", width = NULL
)
),
column(width = 3,
box(
title = "Box title", width = NULL, div(style = "height:150px"),
status = "primary","Box content"
)
Desired Layout:

Why don't columns spread across page in Shiny?

I thought the full row was 12, so 4 3-wide columns should fill across the whole page, but this doesn't.
library(shiny)
fluidPage(
mainPanel(
fluidRow(
column(3,
textInput("user_id", "User ID", width = NULL)
),
column(3,
textInput("name", "Organization name",value = "",width = NULL)
),
column(3,
textInput("address", "Address",value = "",width = NULL)
),
column (3,
textInput("zip", "Zip Code",value = "",width = NULL)
)
) #row
) #panel
) #page
Per default mainPanel has a width of 8. This can be seen when looking at the docs:
?shiny::mainPanel
mainPanel(..., width = 8)
Therefore you have to explicitly state width = 12 inside your mainPanel call.
fluidPage(
mainPanel(
fluidRow(
column(3,
textInput("user_id", "User ID", width = NULL)
),
column(3,
textInput("name", "Organization name",value = "",width = NULL)
),
column(3,
textInput("address", "Address",value = "",width = NULL)
),
column (3,
textInput("zip", "Zip Code",value = "",width = NULL)
)
) #row
, width = 12) #panel
) #page
..should do the trick.

shiny fluidrow column white space

I have a top banner that I want to split into two separate sections representing two different inputs. To do this, I've created a fluidRow and with two columns, one for each input. However, as it is now there is a little bit of white space between the columns, despite putting offset = 0. Is there any way to remove this white space so that the columns are immediately next to one another?
colors = c("green","blue","red")
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("Info",
fluidRow(
column(width = 6, offset = 0,
div(style = "height:50px;width:100%;background-color: #999999;border-style: solid;border-color: #000000",
tags$h3("Section 1")
)
),
column(width = 6, offset = 0,
div(style = "height:50px;width:100%;background-color: #999999;border-style: solid;border-color: #000000",
tags$h3("Section 2")
)
)
),
fluidRow(
column(width = 6, offset = 0,
div(style = "height:50px;width:100%;background-color: #999999;border-style: solid;border-color: #000000",
selectInput(inputId = "color",label = "color:",
choices = colors,
selected = colors[2],
multiple = FALSE)
)
),
column(width = 6, offset = 0,
div(style = "height:50px;width:100%;background-color: #999999;border-style: solid;border-color: #000000",
selectInput(inputId = "points",label = "Number of Points:",
choices = c("30","60","90"),
selected = "10",
multiple = FALSE) )
)
),
br(),
br(),
fluidRow(
actionButton(inputId = "go",
label = "Update"
)
),
fluidRow(
plotOutput("plot", width = "100%")
)
)
)
)
server <- function(input, output,session) {
data = eventReactive(input$go, {
var1 = rnorm(isolate(as.numeric(input$points)),5)
cat1 = c(rep("red",length(var1)/3),rep("blue",length(var1)/3),rep("green",length(var1)/3))
data = cbind.data.frame(var1,cat1)
plotdata = data[which(data$cat1 ==isolate(input$color)),]
}
)
output$plot = renderPlot({
plotdata = data()
plotcol = isolate(input$color)
plot(plotdata$var1, col = plotcol)
})
}
shinyApp(ui = ui,server = server)
The white space is the padding of the column div. To remove that, use
column(width = 6, offset = 0, style='padding:0px;', ...)

Resources