I am interested in removing or hiding the side arrows that appear when you use numericInput() with shiny. I will attach an image of the arrows that I am referring to so everyone can understand which part I would like to remove/hide. After reading the documentation, it does not appear that there is an option to remove these arrows. So I am wondering if there is a way to use CSS to remove these arrows. I did see one other post that asked a similar question. However, I am only interested in using numericInput().
I will attach some sample code. The code essentially does nothing but it will give you a reproducible example.
library(shiny)
server <- function(input, output){
}
ui <- fluidPage(
titlePanel("Test1"),
sidebarLayout(
sidebarPanel(
numericInput("n",
label = h4("Test2"),
min=1,
value = 20),
numericInput("x",
label = h4("Test3"),
min=0,
value = 10),
h4(textOutput("pvalue"))
),
mainPanel(
plotOutput("nullplot")
)
)
)
shinyApp(ui = ui, server = server)
runApp()
WARNING: I have read online that the side arrows do not show up on all web browsers and some versions of RStudio. See here
It does not appear that there is a way to remove the arrows from a numericInput(), however, there is a way to hide them. Just to be clear there is a difference between removing and hiding. Removing the arrows, in theory, should completely remove the code for the arrows. Hiding the arrows will simply mask the code for the side arrows, however, the code will still be present but will not be seen by the user unless they inspect the page.
Below is CSS that can be used to hide the side arrows from numericInput().
tags$head(
tags$style(HTML("
input[type=number] {
-moz-appearance:textfield;
}
input[type=number]::{
-moz-appearance:textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
"))
)
If you wanted to apply this code to the example given in the question, then you could do something like this
library(shiny)
server <- function(input, output){
}
ui <- fluidPage(
titlePanel("Test1"),
sidebarLayout(
sidebarPanel(
tags$head(
tags$style(HTML("
input[type=number] {
-moz-appearance:textfield;
}
input[type=number]::{
-moz-appearance:textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
"))
),
numericInput("n",
label = h4("Test2"),
min=1,
value = 20),
numericInput("x",
label = h4("Test3"),
min=0,
value = 10),
h4(textOutput("pvalue"))
),
mainPanel(
plotOutput("nullplot")
)
)
)
shinyApp(ui = ui, server = server)
runApp()
Overall this is just a workaround because there is no option to remove the side arrows.
Related
I want to style a shiny input from dqshiny package in my Shiny app as below -
library(shiny)
library(dqshiny)
opts <- sapply(1:100000, function(i) paste0(sample(letters, 9), collapse=""))
shinyApp(
ui = fluidPage(
autocomplete_input("auto1", "Unnamed:", opts, max_options = 1000)
),
server = function(input, output, session) {
}
)
I want to 2 things to achieve -
Want to change the highlight color in the suggestion field from yellowish to green
Also want to change the distance between the input field and the suggestion container with let say 10px.
I have a few other Widgets in my App, so above modified styling should not impact other widgets.
Is there any way to achieve this?
Any pointer will be highly appreciated.
Easiest way is just adding the CSS directly into the header. There's a really useful article about styling Shiny apps here.
library(shiny)
library(dqshiny)
opts <- sapply(1:100000, function(i) paste0(sample(letters, 9), collapse=""))
shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML(
'
.autocomplete-items div:hover {
background-color: green;
}
#auto1autocomplete-list {
margin-top: 10px;
}
'
)
)
),
autocomplete_input("auto1", "Unnamed:", opts, max_options = 1000)
),
server = function(input, output, session) {
}
)
Edit: Based on the comment added "". The code works now.
I am trying to embed a 3D mol viewer in my shiny app as described here:
http://3dmol.csb.pitt.edu/doc/tutorial-embeddable.html
I tried the following code:
library(shiny)
ui <- fluidPage(
mainPanel(
fluidRow(
tags$head(HTML('<script src="http://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script>')),
tags$div(
style="height: 400px; width: 400px; position: relative;",
class='viewer_3Dmoljs',
'data-pdb' ='1YCR',
'data-backgroundcolor' ='0xffffff',
'data-style' ='stick'
))
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
It look like the data-pdb, data-backgroundcolor and data-style are not recognized. If I remove these arguments I get a black box. Anybody knows how I could get this working? Also, would it be possible to direct the load-pdb to a local file?
I want to build a multipage shiny application where I can control which page the user can see. Dean Attali does something similiar in this demonstration app, using shinyjs to hide and show each page.
I suppose there could also be ways to do this by using navbar(), navlist() or tabsetPanel(), if one can hide the navigation bar or the navigation list. Advantages would be to update pages simply via updateTabsetPanel(), updateNavbarPage() or updateNavlistPabel(), and that shinyjs is not neccesary any more.
So my question is: How can I hide the navigation bar of navbarPanel(), for example using CSS?
An example application can be found here: https://shiny.rstudio.com/gallery/navbar-example.html. I tried to include some CSS in this example to hide the navigation bar, but until now I only managed to hide everything (by setting .navbar to visibility:hidden) or everything but the navbar-title (by setting .navbar-nav to visibility:hidden). What is the correct element to hide - or the correct combination of elements to hide and of subelements to make visible again?
EDIT: As Chabo pointed out - the main problem seems to be that when the visibility for the navbar is set to hidden, or even display=none, the app does not set an active tab so nothing else shows up.
#https://shiny.rstudio.com/gallery/navbar-example.html
library(shiny)
ui<- navbarPage("Navbar!",
tags$head(
#here something is wrong.
# .navbar makes everything invisible
#.navbar-nav makes everything invisible but the navbar-title
tags$style(HTML("
.navbar-nav{
visibility: hidden;
}
")
)
),
tabPanel("Plot",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot type",
c("Scatter"="p", "Line"="l")
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("Summary",
verbatimTextOutput("summary")
)
)
server<- function(input, output, session) {
output$plot <- renderPlot({
plot(cars, type=input$plotType)
})
output$summary <- renderPrint({
summary(cars)
})
output$table <- DT::renderDataTable({
DT::datatable(cars)
})
}
shinyApp(ui, server)
I am using a simple slider bar in a shiny app to define a value range. I have noticed that you can quite usefully slide the range without changing the start and end value individually (by holding the blue region of the slider bar). However, when I have implemented this feature, users have complained that this functionality is not obvious.
To make this functionality more obvious, I would like the cursor to change to a 'move' symbol e.g. when the the cursor hovers over the blue region.
Here is some simple code to modify.
library(shiny)
ui <- fluidPage(
sliderInput(inputId = 'slider1',
label = 'slider input',
min = 0, max =100,
value = c(10,90)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
I don't think you will be able to do this.
library(shiny)
ui <- fluidPage(
tags$style(
'#test {
cursor: crosshair;
color: red;
}'
),
div(id="test",sliderInput(inputId = 'slider1',
label = 'slider input',
min = 0, max =100,
value = c(10,90))
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
This code changes the cursor inside a div with the slider, and the cursor still reverts to the special shiny slider cursor when you hover over the blue bar. In the shiny source code there is already a unique cursor programmed for the slider, so I don't think you will be able to override that, at least not easily.
Is there a way to color fileInput button in R shiny? It looks like it is possible as shown here on this page on github. However I cannot find the code for this to be done.
This is the simple application that I would like to modify to have the button and progress bar colored red.
In ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel("Test"),
fileInput("Test","")
))
and server.R
library(shiny)
shinyServer(
function(input, output) {
}
)
Thanks for any advice.
You can use standard Bootstrap classes to style action buttons:
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
actionButton("infoButton", "Info", class="btn-info"),
actionButton("warningButton", "Warning", class="btn-warning"),
actionButton("successButton", "Success", class="btn-success"),
actionButton("dangerButton", "Danger", class="btn-danger"),
actionButton("defaultButton", "Default", class="btn-default"),
actionButton("primaryButton", "Primary", class="btn-primary")
)),
server=shinyServer(function(input, output, session){
})
)
Regarding file inputs as far as I know it is not possible without using CSS directly. Page you've linked is an opened pull-request and it doesn't look like it will be merged soon.
This answer provides a good description how to create fancy upload buttons with bootstrap. It should work just fine in Shiny as well.
CSS could be used in shiny to custom your fileInput widget !
Use the following code in order to color it in red.
NB - Any browser you're using to view the app should have developer tools that let you inspect elements and see styles applied to any element. You have to right click on the relevant element and choose inspect !
library(shiny)
ui <- fluidPage(
fileInput(inputId = "Test",label = ""),
tags$style("
.btn-file {
background-color:red;
border-color: red;
}
.progress-bar {
background-color: red;
}
")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)