Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectInput loading slow 60000 items #1963

Closed
Jemkon opened this issue Feb 28, 2018 · 5 comments
Closed

SelectInput loading slow 60000 items #1963

Jemkon opened this issue Feb 28, 2018 · 5 comments

Comments

@Jemkon
Copy link

Jemkon commented Feb 28, 2018

Hi,
I am using development version of shiny 1.0.5.9000. I have 60000 items in my selectInput and its extremely slow.

Here is the code:
sever.R

    output$choose_Genes <- reactiveUI(function() {

    #selectInput(inputId = "Genes", label = "Genes of interest", multiple = TRUE, choices = c("Select Gene", as.list(GeneNames))
    selectizeInput(inputId = "Genes", label = "Genes of interest", multiple = TRUE, choices = c("Select Gene", as.list(GeneNames)),
      options = list(maxOptions = 100))                          
    })

ui.R

    uiOutput("choose_Genes")

The GeneNames is the list of 60000 genes. I have also used selectizeInput but still very slow.

Any idea How I can improve the loading time.

Many thanks.

@jcheng5
Copy link
Member

jcheng5 commented Feb 28, 2018

See the section on server-side selectize here: https://shiny.rstudio.com/articles/selectize.html

@jcheng5 jcheng5 closed this as completed Feb 28, 2018
@Jemkon
Copy link
Author

Jemkon commented Feb 28, 2018

Thanks jcheng5. I have changed the code according to the server-side selectize. But i got following error.

Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

Do I need to put updateSelectizeInput(session, 'Genes', choices = c('Select Gene', as.list(GeneNames)), server=TRUE) into observe function?

I have placed it in server function.

Thanks.

@wch
Copy link
Collaborator

wch commented Feb 28, 2018

Yes, you need to put updateSelectizeInput() in an observe().

EDIT: sorry, I was wrong -- it doesn't need to go in an observe function. Here's a minimal example:

shinyApp(
  fluidPage(
    selectizeInput("foo", "Foo", choices = NULL)
  ),
  function(input, output, session) {
    updateSelectizeInput(session, 'foo', choices = c("a", "b"), server = TRUE)
  }
)

@Jemkon
Copy link
Author

Jemkon commented Feb 28, 2018

Hi wch,
Not working. still got the same error. If I put it in observe function then I dont get error but the selectizeInput is empty.

ui.R

    uiOutput("selectGenes")

server.R

    server <- function(input, output, session) {
            updateSelectizeInput(session, 'Genes', choices = c('Select Gene', as.list(GeneNames)), server=TRUE)

           output[["selectGenes"]] <- renderUI({
                     selectizeInput(inputId = "Genes", label = "Genes of interest", choices = NULL)
               })
        }

Anything wrong with the code?

Many thanks.

@wch
Copy link
Collaborator

wch commented Feb 28, 2018

The problem is that the updateSelectizeInput runs as soon as the app starts, before the selectizeInput is rendered on the page (because it is rendered with renderUI). If selectizeInput were directly in the UI (that is, not with renderUI), then it would work without putting updateSelectizeInput in observe()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants