1
votes

I am able to generate different choices dynamically using renderUI. Now, I wish to use the selected input and dynamically change the output on the main panel

The selectInput contains a list of different databases. By default, I use the latest database but I want to provide the user the option of using previous databases. These previous databases are shown in the selectInput drop down menu. As mentioned earlier I can display all the different databases but I can't choose one and change the mainPanel output based on the selected choice.

This is my ui.R

shinyUI(fluidPage(

  # Application title
  titlePanel("Fill Traffic Analysis"),

  # Sidebar with a slider input for number of bins 
  sidebarLayout( 
    sidebarPanel(
      sliderInput("mkts",
                  "Percent of outside Fill traffic",
                  min = 0,
                  max = 100,
                  value = 60),
      helpText("The following list will be generated dynamically"),
      uiOutput("vx"),
      #downloadButton("downloadData", "Download"),
      width=2
    ),

    # Show a plot of the generated distribution 
    mainPanel(
      h1("Database"),
      h2(textOutput("database")),
      plotOutput("egressMkts.FillTraffic", width = "125%", height = 720)
    )
  )
)
)

This is my server.R

shinyServer(
  function(input, output) {

  tryCatch({


    #Let's set the working directory to /data which is where the database files are stored
    setwd("/data")
    #Find the first 10 files with the string "router" in it
    files <- system("ls -lt | grep \"router\" | head", intern=TRUE)
    pos=regexpr('router2router', files[1])
    database <- substr(files[1],pos,nchar(files[1]))
    output$database <- renderText(database)

    output$vx <- renderUI({
      selectInput("databaseList","Select a database",choices=substr(files,pos,nchar(files)))
    })

    #database <- get(input$databaseList)

    #Connect to the SQL database
    db<-dbConnect(SQLite(),dbname=database)
    dbListTables(db)
    dbListFields(db,"netflow_table")

    #Query the database 
    query <- "select ingressGW, ingressCDN, ingressOnNet, egressGW, egressCDN, ipbusBytes from netflow_table where ingressCDN NOT LIKE 
\"%notCDN%\" and egressCDN NOT LIKE \"%notCDN%\" "
    raw.traffic.data <- dbGetQuery(db,query)

    .
    .
    .
    .
    .

    output$egressMkts.FillTraffic <- renderPlot({

      #database <- get(input$databaseList)
        .
        .
        .
        .
        .
        .

    })
  },
  error=function(e){
    cat(paste("in err handler\n"),e)
  },
  warning=function(w){
    cat(paste("in warn handler2\n"),w)
  }


  )

}
)
1

1 Answers

0
votes

Try using switch:

selcted_database = reactive(switch(input$databaseList,
                                "DB1" = name_database_1,
                                "DB2" = name_database_2,
                                ...))

M