pickerInput from shinyWidgets package has a placeholder title Nothing selected.
How is it possible to replace it with Pick a choice for example ? I would prefer a solution that uses css or the options of pickerInput, if possible avoid shinyjs.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$head(
tags$style(HTML("
"))
),
pickerInput(
inputId = "mtcInputIndicateur",
label = "Select values",
choices = paste("choice", 1:10),
options = list(`live-search` = TRUE),
multiple = TRUE
)
)
server <- function(input, output){
}
shinyApp(ui, server)
Any help would be greatly appreciated.
Just found the answer, use the parameter title in options.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput(
inputId = "mtcInputIndicateur",
label = "Select values",
choices = paste("choice", 1:10),
options = list(`live-search` = TRUE, title = "Pick a choice"),
multiple = TRUE
)
)
server <- function(input, output){
}
shinyApp(ui, server)
Related
Im trying to limit the max number of choices made by pickerInput() to two in shiny app but I cannot make it work.
library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = colnames(mtcars),
multiple = T,
options = list("max-options-group" = 2)
)
))
)
body <- dashboardBody(fluidPage(
)
)
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
The problem is that you are using "max-options-group" but you are not using any groups in your choices. You must use "max-options" = 2 in the options argument of pickerInput().
For completeness, this is the modified version of your code. We cannot pick more than 2 options with it:
library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = colnames(mtcars),
multiple = T,
options = list("max-options" = 2)
)
))
)
body <- dashboardBody(fluidPage(
)
)
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
Try this
columns <- as.list(names(mtcars))
type <- as.list(1:ncol(mtcars))
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = list(Columns = columns,
Type = type),
selected = list(columns[[1]],type[[1]]),
multiple = T,
inline=TRUE,
options = list("max-options-group" = 1, `style` = "btn-info")
)
))
)
body <- dashboardBody(fluidPage())
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)
I have written a simple example of what I am doing. I have 3000 numbers that I want to show in a selectInput. The numbers have to be in a reactive function, since in my original work, the data is from a file.
My problem is that when I run the app it only appears 1000 numbers, not the entire data (3000 numbers).
I have seen this post Updating selection of server-side selectize input with >1000 choices fails but I don't know how can I do it using uiOutput and renderUI.
Can anyone help me?
Thanks very much in advance
The code:
library(shiny)
ui <- fluidPage(
titlePanel("Numbers"),
sidebarLayout(
sidebarPanel(
uiOutput('selectUI')
),
mainPanel(
)
)
)
server <- function(input, output) {
num <- reactive({
data = c(1:3000)
return(data)
})
output$selectUI <- renderUI({
selectInput(inputId = 'options', "Select one", choices = num())
})
}
# Run the application
shinyApp(ui = ui, server = server)
Use selectizeInput instead of selectInput with the argument options = list(maxOptions = 3000).
Thanks to Stéphane Laurent's answer, the example will be solved like this:
library(shiny)
ui <- fluidPage(
titlePanel("Numbers"),
sidebarLayout(
sidebarPanel(
selectizeInput(inputId = "options", label = "Select one", choices=character(0)),
),
mainPanel(
)
)
)
server <- function(input, output, session) {
num <- reactive({
data = c(1:3000)
return(data)
})
observe({
updateSelectizeInput(
session = session,
inputId = "options",
label = "Select one",
choices= num(), options=list(maxOptions = length(num())),
server = TRUE)
})
}
# Run the application
shinyApp(ui = ui, server = server)
This code will work if you have more than 3000 entries. It will show you ALL the choices that you have. However, if you have a long list of choices (e.g. 60000) it will decrease the speed of your app.
I am new to shiny apps/R and would require your help to address my below scenario.
ui <- fluidPage(
selectInput(inputId = "para1",label = "parameter1", choices = c("var1","Var2")),
selectInput(inputId = "para2",label = "parameter2", choices = c("cars","trucks"))
)
server <- function(input,output,session){
output$text <- renderText("control parameters")
}
shinyApp(ui,server)
my requirement is to show/hide "parameter2" based on selecting the "parameter1" values.
Let's say if I select parameter1=="var1", then show "parameter2" otherwise hide entire "parameter2".
You could use shinyjs::toggle combined with uiOutput:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
selectInput(inputId = "para1",label = "parameter1", choices = c("var1","var2")),
uiOutput("selectPara2")
)
server <- function(input,output,session){
output$selectPara2 <- renderUI(selectInput(inputId = "para2",label = "parameter2", choices = c("cars","trucks")))
shiny::observeEvent(input$para1, {
shinyjs::toggle("selectPara2", condition = input$para1 == "var1")
})
}
shinyApp(ui,server)
note that useShinyjs() needs to be called in the UI for this to work.
I'm unable to select/unselect different columns of mtcars dataset using both radioButtons and selectInput function in Shiny.
Can someone please help me out as i'm stuck on it since last 2 days.
I shall be extremely grateful.
Regards
data(mtcars)
#Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
column(width = 10,
radioButtons(inputId="variables", label="Select variables:",
choices = c("All","mpg","cyl","disp"),
selected = "All", inline = TRUE )),
column(width = 10,
selectInput(inputId = "level", label = "Choose Variables to
display", multiple = TRUE, choices = names(mtcars)[4:11]))),
mainPanel (
h2("mtcars Dashboard"),
DT::dataTableOutput("table"))))
#server
server<-function(input, output) {
output$table <- DT::renderDataTable(DT::datatable(filter='top', editable = TRUE, caption = 'mtcars',
{
data <- mtcars
data<-data[,input$variables,drop=FALSE]
column = names(mtcars)
if (!is.null(input$level)) {
column = input$level }
data
})) }
shinyApp(ui = ui, server = server)
library(shiny)
library(DT)
data(mtcars)
#Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
column(width = 10,
radioButtons(inputId="variables", label="Select variables:",
choices = c("All","mpg","cyl","disp"),
selected = "All", inline = TRUE )),
column(width = 10,
selectInput(inputId = "level", label = "Choose Variables to
display", multiple = TRUE, choices = names(mtcars)[4:11]))),
mainPanel (
h2("mtcars Dashboard"),
DT::dataTableOutput("table"))
))
#server
server<-function(input, output, session) {
data <- mtcars
tbl <- reactive({
if(input$variables=='All'){
data
}else{
data[,c(input$variables,input$level),drop=FALSE]
}
})
output$table <- DT::renderDataTable(DT::datatable(filter='top', caption='mtcars', tbl()))
}
shinyApp(ui = ui, server = server)
Here is what I understand from your requirements, I hope it what you are looking for. Always try to avoid calculations inside render*.
I am trying to add a second inputpanel in my shiny application which content depend on the input of the first inputpanel choice, I tried tout use condional panel with no luck.
ui.R
TO <- read.csv("~/TO/TO/TO.csv", sep=";")
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("dasboard"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("country", label = h4("Pays"),
choices = levels(as.factor(TO$Pays))),
conditionalPanel(
condition = "input.country == 'Allemagne'",
selectInput("to", label = h4("Tour opérateur"),
choices = levels(as.factor(as.character(TO[as.character(TO$Pays)=="Allemagne",]$TO))))),
conditionalPanel(
condition = "input.country == 'Angleterre'",
selectInput("to", label = h4("Tour Operator"),
choices = levels(as.factor(as.character(TO[as.character(TO$Pays)=="Angleterre",]$TO)))))
...
The solution that I found is to create a conditionalPanel for every value of the first inputPanel But is the second inputPanel output is only correct for the first value.
Does anyone have a solution?
I know the approach below is not via the conditional panels, as I think it would be simpler to do it via examples given below.
First you can use updateSelectInput to update your entries, something like this
rm(list = ls())
library(shiny)
runApp(list(
ui = bootstrapPage(
selectInput('data', 'Data', c('mtcars', 'iris')),
selectInput('Cols', 'Columns', "")
),
server = function(input, output, session){
outVar <- reactive({
mydata <- get(input$data)
names(mydata)
})
observe({
updateSelectInput(session, "Cols",choices = outVar()
)})
}
))
Other way you can use renderUI to create the selectInput and populate it like so:
rm(list = ls())
library(shiny)
runApp(list(
ui = bootstrapPage(
selectInput('data', 'Data', c('mtcars', 'iris')),
uiOutput('columns')
),
server = function(input, output){
output$columns <- renderUI({
mydata <- get(input$data)
selectInput('columns2', 'Columns', names(mydata))
})
}
))
Edit: how to add multiple widgets inside the renderUI
You need to wrap your divs inside the tagList() like so:
rm(list = ls())
library(shiny)
runApp(list(
ui = bootstrapPage(
selectInput('data', 'Data', c('mtcars', 'iris')),
uiOutput('columns')
),
server = function(input, output){
output$columns <- renderUI({
mydata <- get(input$data)
tagList(
selectInput('columns2', 'Columns', names(mydata)),
selectInput('columns3', 'Columns 2', names(mydata)))
})
}
))