With Shiny when you use SelectizeInput with multiple = TRUE:
a dropdown menu with all the element appears as soon as you are in
that box.
Then, when you start typing, the result in the dropdown
menu are filtered depending on what you type.
When the list is very long, sometimes the point 1 is pointless. Is it possible to see the dropdown only when you start typing (only from point 2)?
Reproducible example:
ui <- fluidPage(
selectizeInput(
inputId = "TEST", label = NULL, choices = c("aa","ab","ac","dd","de","zzz"),
multiple = TRUE)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
selectizeInput has an options argument, which is a list of parameters to initialize the selectize input. One of these options is openOnFocus which is
Show the dropdown immediately when the control receives focus.
Turning off openOnFocus solves the issue.
selectizeInput(
inputId = "TEST", label = NULL, choices = c("aa","ab","ac","dd","de","zzz"),
multiple = TRUE,
options = list(openOnFocus = FALSE,
#If the user write aa then delete it all, the complete list will show up again,
#use maxOptions to solve this issue
maxOptions = 3))
See the full list here selectize
/
selectize.js.
Related
I want the user to click a button and then the renderDataTable function gets called
This is what I'm doing now:
The UI has this:
ui <- fluidPage(
actionButton("tbl","Show Table"),
DT::dataTableOutput("t_all")
)
Server:
server <- function(input, output){
summary_table_RCT <- eventReactive(input$tbl, {summary_table})
output$t_all <-
DT::renderDataTable(
summary_table_RCT(),
filter = 'top',
class = "cell-border stripe",
rownames = FALSE,
extensions = c("FixedColumns"),
options = list(searchHighlight = TRUE,
regex = TRUE,
scrollX = TRUE,
fixedColumns = list(leftColumns = 5))
)
}
shinyApp(ui, server)
Not sure why it's not working this is almost the same as some of the examples I've seen for eventReactive(). I see the button show up, but it doesn't do anything when clicked.
Found the answer, hopefully someone who has to go through the same frustration finds this before it makes them nuts. But in a different tab in the app, another developer used a submitButton(), which basically interrupts ALL reactive events until the button is pressed. Should only only be used in very simple apps, where you only have one button.
I have a shiny app containing a server-side selectize input with a long list (>10k) of choices.
I would like to update the selection upon clicking a button. Here is a reproducible example
library(shiny)
ui <- fluidPage(
actionButton('buttonid','Button'),
selectizeInput("listid", "A long list", choices = NULL)
)
server <- function(input, output, session)
{
updateSelectizeInput(session, "listid", choices = paste("Item", 1:10000), server = T)
observeEvent(input$buttonid,
{
updateSelectizeInput(session, "listid", selected = "Item 1234")
})
}
shinyApp(ui = ui, server = server)
The above code results in a blank selection when I press the button.
However, if I search for "Item 1234", then change selection, and press the button, now the item gets selected.
Also, trying to select an item between Item 1 and 1000 does not give problems, presumably because 1000 items get loaded at the beginning.
This seems akin to this old bug, but I am not sure if there is a workaround https://github.com/rstudio/shiny/issues/1018
The short answer is explicitly re-specify your choices and server in your update.
server <- function(input, output, session)
{
myChoices <- paste("Item", 1:10000)
updateSelectizeInput(session, "listid", choices = myChoices, server = T)
observeEvent(input$buttonid,
{
updateSelectizeInput(session, "listid",
server = TRUE,
choices = myChoices,
selected = "Item 1234")
})
}
The default for server in updateSelectizeInput is FALSE. This causes the code to drop into a control statement which uses updateSelectInput instead. From the function code
function (session, inputId, label = NULL, choices = NULL, selected = NULL,
options = list(), server = FALSE)
{
...
if (!server) {
return(updateSelectInput(session, inputId, label, choices,
selected))
}
...
This sends a message to the client assuming all the choices are present (but as you mentioned, only the first 1000 are present).
Just setting server = TRUE results in an error when you click the button.
Warning: Error in [.data.frame: undefined columns selected
[No stack trace available]
I didn't fully trace the reason, but it ultimately creates an empty choices data.frame with an attribute denoting the selected value. I'm guessing somewhere else in function calls to the session object, this attribute is being used to try to select a column created from the empty data.frame.
The update function doesn't seem to change the choices stored on the server, so that's presumably why it's there when you search for it. During the changing the selected value, it seems to be trying to select from a NULL list of choices instead of the list of choices on the server.
It seems like you essentially have to recreate your selectizeInput when updating with a selected value beyond your initial list.
You can use maxOptions to render all values, might be enough depending on the size of your choices:
selectizeInput("listid", "A long list", choices = NULL, options = list(maxOptions = 10000))
I need help in adding variables checkbox in r shiny within the tabPanel. I have already developed an r shiny app, in which on one of the page the data is displayed on the basis of some filterers and keywords search box.
So, I want to include one checkbox group of variables for the uploaded file.
I saw some of the solution but, non of them is based on tabPanel. Is it possible to have variable checkBox with tabPanel and how to place this under UI and SERVER. Also, as rest of the development is done so, would like to have solution with tabPanel if possible. Thanks
Tried adding the checkBoxInput but with not working with tabPanel and disturbing the current tabPanel
Below is my UI and SERVER
Here, the complete code is not displayed but, with following ui and server, wanted to add checkBoxInputgroup of variable and it should take the variable values from dfcase().
ui <- tabPanel('Evidence Finder in Background Text',
selectizeInput("Words1",
label="Important Words - Dictionary",
choices= TRUE,
multiple = TRUE,
options = list(maxOptions = 20000)),
DT::dataTableOutput("table2")
)
output$table2 <- DT::renderDataTable(server = FALSE,{
dfcase_bckg = as.data.frame(dfcase())
DT::datatable(dfcase_bckg,
rownames = FALSE,
escape = TRUE,
class = 'cell-border stripe',
selection = "single",
extensions = 'Buttons',
)
}
)
This is the view of the app and to left side i need the list of variables with checkbox
I have created a datatable in an R shiny app at the top of the page with input controls at the bottom that determine the data displayed in that table.
The table is long, and the user must therefore scroll down to access the input controls. But upon changing any single input control, the app will automatically scroll to the top of the page.
How can I prevent automatic scrolling to the top of the page when changing the inputs? (Note that I do not want to delay updating of the table until all inputs are changed by having, for example, an 'Update table' button that must be clicked, in which case automatic scrolling would be OK.)
Note that this hasn't worked for me:
R shiny: how to stop sliderInput label click from causing scroll to top of page?
Example code:
library(shiny)
library(DT)
# Define UI
ui <- shinyUI(
fluidRow(
column(3,
DT::dataTableOutput("exampleOutput"),
numericInput("var", h5("Row value"), value = 100)
)
)
)
server <- function(input, output) {
exampleTable <- reactive({
transactionCostsDataFrame <- data.frame(
"Transaction" = rep(input$var, 100))
})
output$exampleOutput <- DT::renderDataTable(
DT::datatable(exampleTable(), escape = FALSE,
options = list(dom = "t", ordering = FALSE,
bFilter = 0, pageLength = 100))
)
}
# Run the app
shinyApp(ui = ui, server = server)
selectize.js has an item creation option as mentioned on http://brianreavis.github.io/selectize.js/. I'm trying to add the same feature in an R Shiny implementation of selectize but unable to figure out how.
Thanks for your help!
PS: Some more details about what exactly I'm doing - I have some sort of free text vector that I let the user add to. However, I want Shiny to prompt the user with the existing free text values that have previously been added in case the user wants to repeat one of them.
All you have to do is to set create option to true:
library(shiny)
shinyApp(
server = function(input, output, session) {
observe({ print(input$foo) })
},
ui = fluidPage(
selectizeInput(
"foo", "foo", c(), selected = NULL, multiple = TRUE,
options = list(create = TRUE))
)
)