I have a shiny app that has a selectizeInput
widget which gets its about 26000 choices from a remote database in form of reactive data.
The use of a remote database and reactivity is to avoid lagging and slowness when loading the choices.
The issue is that when launched on the desktop locally, it works fine but when uploaded on shinyapps.io the widget does not present to the user all available choices.
I have played around with the widgets attributes to no avail, for example, setting SERVER =TRUE
and so on.
I have put the code I am using below as well as a link to the data I want loaded to the selectizeInput
as choices.
UI part
library(shiny)
library(DBI)
library(RMySQL)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
skin="yellow",
dashboardHeader( ),
#sidebar content
dashboardSidebar(
sidebarMenu(
selectInput(
inputId="selectData",
label=" ", selected = NULL,
choices=c( "title" )),
menuItem("Titles Search", tabName = "Titles", icon = icon("font"))
)
),
dashboardBody(
tags$head(
tags$style(HTML("
.content-wrapper {
background-color: green !important;
}
.main-header {
background-color: red !important;
}
"))
),
tabItems(
tabItem(tabName = "Titles",
fluidRow(
column(width=3,
box(
title=" ",
solidHeader=TRUE,
collapsible=TRUE,
width=NULL,
selectizeInput('titles', label = "Search by title",
choices = NULL, options = list(
placeholder = 'Type the title', maxOptions = 1000,
maxItems = 100,multiple = F, searchConjunction = 'and')),
tags$style(type="text/css",
".selectize-
input::after{visibility:hidden;};"
)
)
)
)
)
)
)
)
Server part
library(shiny)
library(DBI)
library(RMySQL)
library(shinydashboard)
library(shinyjs)
shinyServer(function(input, output, session) {
con <- dbConnect(MySQL(), user='XXXX',
port = 3306, password='XXXXX',
dbname='XXXXXX',
host='XXXXXXXX' )
query <- function(...) dbGetQuery(con, ...)
on.exit(dbDisconnect(con), add = TRUE)
selectedData <- reactiveValues()
observeEvent(input$selectData, {
con <- dbConnect(MySQL(), user='XXXXXX', port = 3306, password='XXXX', dbname='XXXXX', host='XXXXXXX' )
query <- function(...) dbGetQuery(con, ...)
on.exit(dbDisconnect(con), add = TRUE)
if (input$selectData == "title") {
selectedData$titledata <- query("SELECT titles FROM titles ;")
}
updateSelectizeInput(session, "titles",
choices = as.character(unique(selectedData$titledata$titles)),
server = TRUE)
})
session$onSessionEnded(function() { dbDisconnect(con) })
})
What am I doing wrong? Is it a shinyapps.io problem or a coding issue?