Comments (6)
Last multi.js release support a limit
options, so you can do (that's not exactly what you asked, but this is close):
# install dev version
# devtools::install_github("dreamRs/shinyWidgets")
library("shiny")
library("shinyWidgets")
ui <- fluidPage(
multiInput(
inputId = "id", label = "Fruits :",
choices = c("Banana", "Blueberry", "Cherry",
"Coconut", "Grapefruit", "Kiwi",
"Lemon", "Lime", "Mango", "Orange",
"Papaya"),
options = list(limit = 1), # <-------- here
width = "350px"
),
verbatimTextOutput(outputId = "res")
)
server <- function(input, output, session) {
output$res <- renderPrint({
input$id
})
}
shinyApp(ui = ui, server = server)
from shinywidgets.
Hi @ViolaPsch ,
No, there's no options to set a minimum number of items to be selected. I don't think I know of any widget with this option.
My solution will be to display an informative text under the widget and then use req(length(input$id) > 3)
in reactive context to be sure there more than 3 items selected (you can also look to ?shiny::need
).
Here's an example with an alert info:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$h3("Fruit selector"),
fluidRow(
column(
width = 4,
multiInput(
inputId = "id",
label = "Fruits :",
choices = c("Banana", "Blueberry", "Cherry",
"Coconut", "Grapefruit", "Kiwi",
"Lemon", "Lime", "Mango", "Orange",
"Papaya"),
selected = "Banana",
width = "100%"
),
uiOutput(outputId = "info")
),
column(
width = 8,
verbatimTextOutput(outputId = "res")
)
)
)
server <- function(input, output, session) {
output$info <- renderUI({
if (length(input$id) < 3) {
alert(
icon("info"),
"You need to eat at least 3 fruits! (", 3 - length(input$id), "more to pick)",
status = "info"
)
}
})
output$res <- renderPrint({
input$id
})
}
shinyApp(ui = ui, server = server)
Victor
from shinywidgets.
I'm glad you find the package useful!
I don't think that's possible with this plugin... (without hardcoding it in js, which can be a solution but will take some times).
You can find the JavaScript lib here : https://github.com/Fabianlindfors/multi.js
I'll look into alternative or similar widgets.
Victor
from shinywidgets.
Hey,
I use multiInput
for displaying flags and am wondering whether there is a way to do the opposite @BetweenTwoTests aked: Can I set a minimum for the number of items that should be selected?
Thank you 🙏,
Viola
from shinywidgets.
Thank you, @pvictor! This is a good idea. 🙂
from shinywidgets.
I believe the "limit" option no longer works. It was working for me a few months ago. After I updated R, it is not working. I ran the example @pvictor provided back in 2018 and experienced the same issue. No items in choices are able to be selected or deselected.
from shinywidgets.
Related Issues (20)
- Spinner remains visible when rendering DT HOT 2
- [docs] deprecated docs in switchInput() HOT 1
- virtualSelectInput(..., multiple = TRUE, showValueAsTags = TRUE, updateOn = "close") -> Removing tags does not have an effect on `input$...` HOT 1
- `sliderTextInput` compatibility problem on Quarto doc in the argument `choices`. HOT 2
- `updateAirDateInput()` does not update value if no options provided HOT 2
- Button width not working in dashboard sidebar
- updateSliderTextInput() doesn't have a default argument for session HOT 1
- radioGroupButton rendered incorrectly by renderUI when used in conjunction with jsTreeR HOT 1
- updateAirDateInput() behaviour inconsistent when server and client timezones differ
- Bug: Special characters in virtualSelectInput HOT 2
- airDatePicker selecting dates works incorrectly in Docker container HOT 2
- Compatibility of WinBox with Dark Theme in bs4Dash HOT 1
- Choices max size? HOT 1
- `updateAirDateInput` does not fully overwrite `disabledDates` HOT 2
- Virtural select input dropdown appears behind slider inputs HOT 2
- Calling `show_toast` before previous toast disappears causes "Duplicate IDs found" error to appear
- `airDatepickerInput()` Clear button does not clear the blue highlighting HOT 1
- airDatepickerInput() can't show month number but use 00 instead HOT 2
- `updateAirDateInput` does not fully overwrite `value` HOT 1
- Not possible to clear the airdatepicker HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shinywidgets.