Reactive output inside tabPanel using user input

139 Views Asked by At

I am trying to create an application which filters data by first choosing a subset of data which produced in a separate script do_data.R and then filters this subset by several indicators selected by users.

My reproduced example is shown below:

My ui.R file is:

source("do_label.R")

shinyUI(fluidPage(theme = shinythemes::shinytheme("lumen"),
fluidRow(
column(width = 8, includeMarkdown("intro_data.md")),
column(width = 4, includeHTML("intro_logo.html"))
), 
sidebarLayout(

sidebarPanel(
  selectInput("indicator", "Indicator:", choices = indicator),
  selectInput("category", "Category:", choices = category)
  sliderInput("year", "Year:", min = 2011, max = 2016, value = 1, sep = "")
),
mainPanel(
tabsetPanel(
tabPanel('Data',    DT::dataTableOutput('ex1')),
tabPanel('Graphs',      DT::dataTableOutput('ex2'))
)
))
))

and my server.R file is:

library(readr)
library(dplyr)

source("do_data.R")

# Load the dataset
loadData <- function() {
df <- surveydata
return(df)
}

getTable <- function(df, reaction){

if(input$indicator == "df1")
return(df1)
else
return(df1)  
}


##### GLOBAL OBJECTS #####

# Shared data
globalData <- loadData()

##### SHINY SERVER #####
# Create shiny server.
shinyServer(function(input, output) {
cat("Press \"ESC\" to exit...\n")
# Copy the data frame 
localFrame <- globalData


getReaction4 <- reactive({
return(list(indicator = input$indicator
))
}) # getReaction4 
# Output table.
output$table = DT::renderDataTable({print(getTable(localFrame,   getReaction4()))} # output table

})

My problem is that my subsets df1 and df2 are not shown at all and sidebarPanel seems to be completely not functional. Can you help please by some basic advice on what I missing here?

Regards

0

There are 0 best solutions below