I have a rather simple Shiny app that consists of a table that reacts to three filters and it works just fine. However, I need it to have at least a mild layer of security, so I added a Login module with the Shinyauthr package adapting my app code to the one posted in GitHub - PaulC91/shinyauthr: R package with shiny authentication modules.
The problem is that when I run the app the filters and the table appear and it seems to work fine but still I get the following error:
"Warning: Error in : Problem with filter()
input ..1
. i Input ..1
is conditional(input$selector_destiny != "", Destiny_flight == input$selector_destiny)
. x argument has length 0."
I've looked at many posts online but since I'm new to Shiny, I'm still unable to figure out what is wrong with my code. Any help solving this issue would be great!
Here is the code for the app with the login form:
library(DT)
library(shiny)
library(dplyr)
library(shinyjs)
#data
my_data <- data.frame(
"Destiny_flight" = as.character(c("CDB", "OPF", "ABC", "CDB", "OPF")),
"Origin" = as.character(c("ABC", "CDB", "CDB", "OPF", "ABC")),
"Date_flight" = as.Date(c("2020-01-24", "2021-06-09", "2021-03-19", "2020-12-24", "2021-01-08"),format = "%Y-%m-%d")
)
# dataframe that holds usernames, passwords and other user data
user_base <- tibble::tibble(
user = c("user1", "user2"),
password = c("pass1", "pass2"),
permissions = c("admin", "standard"),
name = c("User One", "User Two"))
# ui ----
ui <- navbarPage(title = "Title2",
tabPanel(title = "Title2",
useShinyjs(),
div(class = "container",
div(
class = "pull-right", shinyauthr::logoutUI(id = "logout")),
shinyauthr::loginUI(id = "login")),
uiOutput(outputId = "row_input"),
DTOutput('table_final')))
# Server ----
server <- function(input, output, session) {
# call the logout module with reactive trigger to hide/show
logout_init <- callModule(
shinyauthr::logout,
id = "logout",
active = reactive(credentials()$user_auth))
# call login module supplying data frame, user and password cols
# and reactive trigger
credentials <- callModule(
shinyauthr::login,
id = "login",
data = user_base,
user_col = user,
pwd_col = password,
log_out = reactive(logout_init()))
conditional <- function(condition, success) {
if (condition) success else TRUE}
reactiveDf <- reactive({
my_data %>%
dplyr::filter(
conditional(input$selector_destiny != '', Destiny_flight == input$selector_destiny),
Date_flight >= input$dateRange[1] & Date_flight <= input$dateRange[2]
)
})
# App ----
output$table_final <- renderDT({
req(credentials()$user_auth)
reactiveDf()
})
output$row_input <- renderUI({
req(credentials()$user_auth)
fluidRow(
column(width = 6,
selectInput(
"selector_destiny",
label = "Destiny",
choices = c('',unique(unlist(my_data$Destiny_flight))),
multiple = FALSE,
selectize = TRUE)),
column(width= 6,
dateRangeInput('dateRange',
label = 'Date',
start = as.Date('2020-01-24') ,
end = as.Date('2021-06-09'),
width = '1500%')))
})
}
# Run app
shinyApp(ui = ui, server = server)
````