rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
894 stars 298 forks source link

Retrieving the plots in dynamics tabs, data being present in database #315

Open kartikchhabra opened 5 years ago

kartikchhabra commented 5 years ago

I have 2 tables one containing the tab name and its corresponding key and other table containing the data for which i will plot the data.

Here is 1st table

+-----------+--------------------+-------+
| row_names | available_scenario | s_key |
 +-----------+--------------------+-------+
| FALSE     | aaa                |     1 |
| FALSE     | kart               |     2 |
| FALSE     | final              |     3 |
+-----------+--------------------+-------+

Here is 2nd table which is containing the data for plots

 +-------------+------+--------+--------------+
| Overbooking | Cost | Profit | s_key         |
+-------------+------+--------+--------------+
|           1 |    0 |  22000 |            1 |
|           2 |    0 |  30600 |            1 |
|           3 |    0 |  23800 |            1 |
|           4 |    0 |  32600 |            1 |
|           5 |    0 |  30600 |            1 |
|           6 |    0 |  33200 |            1 |
|           7 |    0 |  32200 |            2 |
|           8 |    0 |  31800 |            2 |
|           9 |    0 |  31800 |            2 |
|          10 |    0 |  28200 |            2 |
|          11 |    0 |  28800 |            2 |
|          12 |    0 |  33200 |            2 |
|          13 |    0 |  31600 |            2 |
|          14 |    0 |  30400 |            3 |
|          15 |    0 |  33600 |            3 |
|          16 |    0 |  26200 |            3 |
|          17 |    0 |  33000 |            3 |
|          18 |    0 |  25200 |            3 |

Here is sample code

   library("shiny")
  library("shinydashboard")
  library("pool")
 library("DBI")
 pool <- dbPool(drv = RMySQL::MySQL(),dbname = "demo",host =       "db.cr7dht.us-east-2.rds.amazonaws.com",username = "kak",password =    "1278",    port = 3306)
 mychoices = dbGetQuery(pool,"select available_scenario from sc;")
   ui <- (fluidPage(
    titlePanel("Demonstration of renderUI in shiny - Dymanically creating            the       tabs based on user inputs"),
     sidebarLayout(
     sidebarPanel(
     selectInput('n', "available scenarios", choices = mychoices,        multiple      = TRUE),
    verbatimTextOutput("selected")

      ),
   mainPanel(
     uiOutput('tabs')
  )
 )
))
server <- (function(input,output,session){
 output$tabs = renderUI({
   observe({
   updateSelectInput(
session, "n", choices = mychoices
 )
 })
Tabs <- lapply(paste("tab name", 1:input$choices, sep=" "), tabPanel)
do.call(tabsetPanel, Tabs)

  })
})
shinyApp(ui, server)

here when i click in select input function and select the corresponding scenario name then i would plot the graph by the use of plot function(that is not problem). Now i am getting trouble that how can i link tab name with 1st table.After linking tab name and 1st table i can use 2nd table by foreign key.Hope i am explaining my problem. Can anyone help.

alandipert commented 5 years ago

Hi, thank you for posting this question, but your example appears not to run without extensive modification. As such it's hard for me to understand your question, because it depends on me being able to run your app and see its behavior.

Would it be possible for you to supply a standalone, working example of the problem? That would help me greatly to understand your problem, and empower me to provide a solution.

Preferably, your example would not rely on me doing data entry or connecting to a database. Thank you in advance for the additional help understanding.