User Input Based on selected variables

I am trying to build a prediction app. user selects variables for fitting the model. The same variables will be used for the prediction. In my prediction tab pickerInput gives me all variables selected by the users. When I am trying to use conditionalPanel, its not working. It's like this condition is always true no matter if you select that variable or not.

tabPanel(title  = h4('Prediction', style = 'font-family: Times New Roman; background-color:lighblue; font-weight: bold; font-size:3vw'),
                              fluidRow(
                                box(pickerInput(inputId = 'predVar',
                                                label = '',
                                                choices = colnames(df[, c(1:10)])),
                                    actionButton("add_btn", "Add"),
                                    actionButton("delete_btn", "Delete"),
                                    actionButton("predict_btn", "Predict")
                                ),
                                box(
                                  conditionalPanel("input.predVar == 'fixed.acidity'",
                                                  numericInput(inputId = 'acid',
                                                               label = 'FA',
                                                               value = 0))
                                )
                                
                              )

Welcome to the community @KayP! The code appears to be working as intended for me. I notice that if fixed.acidity is not in single quotes, the condition always acts as true. However, the way it's written, within single quotes, the app works. Below is a full functioning app that behaves as expected. If you run this example, do you still experience the same issue?

library(shiny)
library(shinyWidgets)
library(tidyverse)

df = dplyr::starwars[,1:9] |> mutate(fixed.acidity = 5)

ui <- fluidPage(
  tabPanel(title  = h4('Prediction', style = 'font-family: Times New Roman; background-color:lighblue; font-weight: bold; font-size:3vw'),
           fluidRow(
             box(pickerInput(inputId = 'predVar',
                             label = '',
                             choices = colnames(df[, c(1:10)])),
                 actionButton("add_btn", "Add"),
                 actionButton("delete_btn", "Delete"),
                 actionButton("predict_btn", "Predict")
             ),
             box(
               conditionalPanel("input.predVar == 'fixed.acidity'",
                                numericInput(inputId = 'acid',
                                             label = 'FA',
                                             value = 0))
             )))
  )

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

When 'fixed.acidity' is not selected.

When 'fixed.acidity' is selected.

Not sure why I am facing problems with the same code. Maybe the way I am accessing the input vector is incorrect!!

I will try again.. thank you for your help!!

Sorry to hear you're still facing issues. Perhaps try reinstalling shiny, shinyWidgets, and tidyverse and see if that helps.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.