0
votes

I have a Shiny code as like this

library(datasets)
ui <-fluidPage(    
titlePanel("Telephones by region"),
sidebarLayout(      
sidebarPanel(
  selectInput("region", "Region:", 
              choices=colnames(WorldPhones)), checkboxInput(inputId = "Adv",
                                                            label = strong("Advanced"),
                                                            value = FALSE),fileInput("file1", "Choose CSV File",
            multiple = FALSE,accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")),
  hr(),
  helpText("Data from AT&T (1961) The World's Telephones.")),
mainPanel(
  plotOutput("phonePlot")   )))

server <- function(input, output) {

output$phonePlot <- renderPlot({

barplot(WorldPhones[,input$region]*1000, 
        main=input$region,
        ylab="Number of Telephones",
        xlab="Year")})}
shinyApp(ui, server)

I need to implement following modifications

  1. How to disable/enable selectInput and fileInput upon the selection of Advanced checkboxInput. If user choose advanced, the selectInput must be disable (vice versa)

  2. How to use if function for fileInput from user input (Asia,Africa….ect one per line )

1

1 Answers

1
votes

To enable/disable the inputs you can use package shinyjs. Something like this should work:

library(datasets)
library(shiny)
ui <-fluidPage(   
    shinyjs::useShinyjs(),
    titlePanel("Telephones by region"),
    sidebarLayout(      
        sidebarPanel(
            selectInput("region", "Region:", 
                        choices=colnames(WorldPhones)),
            checkboxInput(inputId = "Adv",
                          label = strong("Advanced"),
                          value = FALSE),
            fileInput("file1", "Choose CSV File",
                      multiple = FALSE,accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")),
            hr(),
            helpText("Data from AT&T (1961) The World's Telephones.")),
        mainPanel(
            plotOutput("phonePlot")   )))

server <- function(input, output) {
    
    observe({
        
        if((input$Adv == TRUE)) {
            shinyjs::disable("region")
            shinyjs::disable("file1")
        } else {
            shinyjs::enable("region")
            shinyjs::enable("file1")
        }
    })
    
    output$phonePlot <- renderPlot({
        
        barplot(WorldPhones[,input$region]*1000, 
                main=input$region,
                ylab="Number of Telephones",
                xlab="Year")})}
shinyApp(ui, server)