This is a simplification of my Shiny UI. My issue is that the pull-down menu from the SelectizeInput is hidden. It is a bit of a pain having to scroll down. Also, it just does not look very nice. I have tried playing with the z-index to bring it up front but have not had any success.
This is my code:
library(shiny)
runApp(list(
ui = fluidPage(
tabsetPanel(id = "tabs",
tabPanel("Search",
fluidRow(
column(12,
inputPanel(
selectizeInput("s1", h4("Select State:"),
choices = state.name),
tags$head(tags$style(".selectize-control.single { width: 400px; z-index: 1; }")),
dateInput("day", h4("Input Date:"), value = Sys.Date())
)
)
)
)
)),
server = function(input,output,session)
{
})
)
Basically, I want the SelectizeInput menu to display on top like the DateInput calendar.
Thanks for the help!
Carlos
You can use the options from the selectize.js library https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md . dropdownParentmaybe what you are looking for:
library(shiny)
runApp(list(
ui = fluidPage(
tabsetPanel(id = "tabs",
tabPanel("Search",
fluidRow(
column(12,
inputPanel(
selectizeInput("s1", h4("Select State:")
, options = list(dropdownParent = 'body')
, choices = state.name),
tags$head(tags$style(".selectize-control.single { width: 400px; z-index: 1; }")),
dateInput("day", h4("Input Date:"), value = Sys.Date())
)
)
)
)
)),
server = function(input,output,session)
{
})
)
Alternatively you can look at CSS and something like the overflow attribute. See Dropdowns not extending in shiny tabPanel . So in this case use
tags$head(tags$style(".tab-content {overflow: visible;}")),
Related
Is there way to adjust the width of a well panel as shown in the image below? At the bottom is the code, if the user clicks the "Delete column" action button a conditional panel renders underneath; clicking of any other action button causes the conditional panel to disappear. I'd like the conditional panel to be surrounded in a well panel and am trying to format it nicely.
My guess is this requires some CSS.
Code:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
br(),
fluidRow(
column(2,actionButton("addCol","Add column")),
column(2,actionButton("delCol","Delete column")),
column(2,actionButton("savTbl","Save table")),
column(2,actionButton("clrTbl","Clear table")),
br(),
),
br(),
shinyjs::hidden(
div(id="delPanel",
conditionalPanel(
condition="input.delCol > 0 && !output.hide_panel",
fluidRow(
wellPanel(
column(2,textOutput("delFlag")),
column(3,uiOutput("delCol2"))
)
),
style = "display: none;"
)
)
)
)
server <- function(input,output,session)({
observeEvent(input$delCol,{shinyjs::show("delPanel")})
observeEvent(input$addCol|input$savTbl|input$clrTbl,{shinyjs::hide("delPanel")})
output$delFlag <- renderText("Delete column:")
output$delCol2 <-
renderUI(
selectInput("delCol3",
label = NULL,
choices = c(1,2,3),
selected = "")
)
})
shinyApp(ui, server)
Below is a css solution, thanks to post Shiny wellpanel width:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
br(),
fluidRow(
column(2,actionButton("addCol","Add column")),
column(2,actionButton("delCol","Delete column")),
column(2,actionButton("savTbl","Save table")),
column(2,actionButton("clrTbl","Clear table")),
br(),
),
br(),
shinyjs::hidden(
div(id="delPanel",
conditionalPanel(
condition="input.delCol > 0 && !output.hide_panel",
fluidRow(tags$div(id="pane", # added
wellPanel(
column(2,textOutput("delFlag")),
column(3,uiOutput("delCol2")),
),
tags$style(type="text/css","#pane{font-size:14px;width:565px;}") # added
)
),
style = "display: none;"
)
)
)
)
server <- function(input,output,session)({
observeEvent(input$delCol,{shinyjs::show("delPanel")})
observeEvent(input$addCol|input$savTbl|input$clrTbl,{shinyjs::hide("delPanel")})
output$delFlag <- renderText("Delete column:")
output$delCol2 <-
renderUI(
selectInput("delCol3",
label = NULL,
choices = c(1,2,3),
selected = "")
)
})
shinyApp(ui, server)
I need the following requirement with the R script below. When you click on the sidebar symbol at the top, when dashboard body expands, all widgets are in one line, however when the dashboard body shrinks, the dateRangeInput widget appears in the below line. I want all widgets to appear in one line and resize accordingly. Please help and thanks.
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", fluidPage(
div(style = "display: inline-block;vertical-align:top; width: 600 px;",
selectInput("select1","select1",c("A1","A2","A3")),selected = "A1"),
div(style = "display: inline-block;vertical-align:top; width: 600 px;",
selectInput("select2","select2",c("A3","A4","A5")),selected = "A3"),
div(style = "display: inline-block;vertical-align:top; width: 600 px;",
selectInput("select2","select2",c("A3","A4","A5")),selected = "A3"),
div(style = "display: inline-block;vertical-align:top; width: 600 px;",
selectInput("select2","select2",c("A3","A4","A5")),selected = "A3"),
div(style = "display: inline-block;vertical-align:top; width: 600 px;",
dateRangeInput("daterange1", "Date range:",
start = "2001-01-01",
end = "2010-12-31")
),
status = "primary", solidHeader = T, width = 12, height = 120)
)
))
server <- function(input, output) { }
shinyApp(ui, server)
Some of your code was off such that one didnt even see the box around your inputs.
Besides that: You're somewhat styled divs were not useful in achieving what you desired. Feel free to browse through the shiny layout guide section on the Fluid Grid to explore what possibilities in styling you have by just using the right functions shiny offers.
For the height issue in daterange widgets: The selects have a min-height of 34 pixels. If you also apply that to daterange objects by css, you can have them be the same size.
Corrected code below:
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Data", status = "primary", solidHeader = T, width = 12,
fluidPage(
fluidRow(
column(2, selectInput("select1","select1",c("A1","A2","A3"), selected = "A1")),
column(2, selectInput("select2","select2",c("A3","A4","A5"), selected = "A3")),
column(2, selectInput("select2","select2",c("A3","A4","A5"), selected = "A3")),
column(2, selectInput("select2","select2",c("A3","A4","A5"), selected = "A3")),
column(4, dateRangeInput("daterange1", "Date range:", start = "2001-01-01",end = "2010-12-31")),
tags$head(
tags$style("
.input-daterange input {
min-height: 34px;
}
")
)
)
)
)
)
)
server <- function(input, output) { }
shinyApp(ui, server)
I created a dashboard using shinyDashboard and I have a map with leaflet. The box element used in shinyDashboard creates a fixed height of 400px for the map.
I would like the map to be 90vh so that it covers most of the screen, and so I wrote this on the UI file:
tabItem(tabName = "widgets",
fluidPage(
fluidRow(
tags$head(tags$style(type = "text/css",'
#geomap {
height: 90vh;
}
')),
box(title = "Geographical distribution",
leafletOutput("geomap")
)
)
)
)
Now, when I inspect the page, I can see that the property was passed onto the #geomap id, but it is overridden for some reason
!
Also, here is the node
.
I have overridden classes before successfully, so I don't understand how an ID can't be overridden. Any ideas?
Thank you!
EDIT: Here's an example code:
library(shiny)
library(shinydashboard)
library(leaflet)
server <- function(input, output, session) {
output$geomap <- renderLeaflet({
m <- leaflet(data) %>%
addProviderTiles("CartoDB.Positron")
})
}
ui <- dashboardPage(skin = "black",
dashboardHeader(title = "Test"),
dashboardSidebar(
sidebarMenu(
menuItem("Map distribution", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "widgets",
fluidPage(
fluidRow(
tags$head(tags$style(HTML('
.col-sm-6 {
width: 100%;
}
'))),
box(title = "Geographical distribution",
leafletOutput("geomap")
)
)
)
)
)
)
)
shinyApp(ui, server)
I've got a shiny application like this:
server.R:
library(shiny)
function(input, output) { NULL }
and ui.R:
library(shiny)
pageWithSidebar(
headerPanel("side-by-side"),
fluidRow(
column(2),
column(4,
wellPanel(
selectInput(inputId = "options", label = "some text",
choices = list(a = 0, b = 1)))
)
),
fluidRow(
h3("bla bla")
)
)
And I would like to have the label of selectInput next to it, not above. Do you know how to do it?
I've found this: Positioning Shiny widgets beside their headers
but it doesn't work for me.
There's multiple ways of doing this, here's one:
library(shiny)
server <- shinyServer(function(input, output) { NULL })
ui <- shinyUI(
pageWithSidebar(
headerPanel("side-by-side"),
sidebarPanel(
fluidRow(
tags$head(
tags$style(type="text/css", "label.control-label, .selectize-control.single{ display: table-cell; text-align: center; vertical-align: middle; } .form-group { display: table-row;}")
),
column(2),
column(4,
selectInput(inputId = "options", label = "some text",
choices = list(a = 0, b = 1))
)
)),
mainPanel(
fluidRow(
h3("bla bla")
))
)
)
shinyApp(ui=ui,server=server)
If you don't want to mess with shinys default CSS you can just leave the label empty and create a label next to it instead of forcing the existing label to the side.
I know there are a few posts about this issue, but I'm not getting why my code is not working. I have an app in Shiny that I'd like to have contain a conditional sidebar panel, that shows different controls based on which panel in the main panel is currently selected by the user. I thought the code below would work, but the app only displays conditional panel 1 (as defined below). Can anyone give me any advice? Thanks.
my ui.R:
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("Spatially Balanced Sampling Tool"),
sidebarPanel(
tags$head(
tags$style(type="text/css", "select { max-width: 175px; }"),
tags$style(type="text/css", "textarea { max-width: 100px; }"),
tags$style(type="text/css", ".jslider { max-width: 120px; }"),
tags$style(type='text/css', ".well { max-width: 200px; }"),
tags$style(type='text/css', ".span4 { max-width: 200px; }")
),
conditionalPanel(condition="input.conditionedPanels == 1",
fileInput('file1', 'Choose .ZIP Shapefile:', multiple=TRUE,
accept=c('binary'))
),
conditionalPanel(condition="input.conditionedPanels == 2",
numericInput("pts", "# of sampling points per stratum:", 50),
numericInput("oversamppts", "# to OVER sample (optional):", 5),
submitButton("Generate Points"),
helpText("WORK DAMMIT")
)),
mainPanel(
tabsetPanel(
tabPanel("Instructions",
includeHTML("instructions.html"),
div(id="linkToMap", tags$a("Click here to see a map of your input data and create points")),
div(id="linkToPoints", tags$a("Click here to see table of created points")),
value=1
),
tabPanel("plot", helpText("Map of input polygons"),
plotOutput("plot"),
p(paste("polygons by strata")),
value=2
),
tabPanel("View Points", helpText("suggested sampling points"),
tableOutput("pointdata"),
HTML("<script>$('#linkToMap').click(function() {
tabs = $('.tabbable .nav.nav-tabs li')
tabs.each(function() {
$(this).removeClass('active')
})
$(tabs[1]).addClass('active')
tabsContents = $('.tabbable .tab-content .tab-pane')
tabsContents.each(function() {
$(this).removeClass('active')
})
$(tabsContents[1]).addClass('active')
$('#plot').trigger('change').trigger('shown')
})</script>
"),
HTML("<script>$('#linkToPoints').click(function() {
tabs = $('.tabbable .nav.nav-tabs li')
tabs.each(function() {
$(this).removeClass('active')
})
$(tabs[2]).addClass('active')
tabsContents = $('.tabbable .tab-content .tab-pane')
tabsContents.each(function() {
$(this).removeClass('active')
})
$(tabsContents[2]).addClass('active')
$('#pointdata').trigger('change').trigger('shown')
})</script>
"),
value=2
),
id = "conditionedPanels"))))
It looks like the conditionalPanel statement is looking for the name of the tabPanel.
# This will not work
condition="input.conditionedPanels == 1" #wrong
When I switched the condition in your conditionalPanel statement to test for the name of the tab, as opposed to the value, it worked.
I scooped out everything extraneous and got your UI.R to work conditionally as intended. You can use this as a starting point and go from here.
UI.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Spatially Balanced Sampling Tool"),
sidebarPanel(
conditionalPanel(condition="input.conditionedPanels == 'Tab1'",
helpText("TAB 1")
),
conditionalPanel(condition="input.conditionedPanels == 'Tab2'",
helpText("TAB 2 SELECTED")
)
),
mainPanel(
tabsetPanel(
tabPanel("Tab1",
p(paste("Tab 1 text")
)
),
tabPanel("Tab2", helpText("Map of input polygons"),
p(paste("polygons by strata")
)
),
id = "conditionedPanels"
)
)
))