Hi All,
Can anyone help me in accessing input from another R file . I am trying to call df
based on input selected from the filters
app.R
library(shinydashboard)
library(shiny)
library(dplyr)
source("fun.R")
ui <- navbarPage('TEST', id='page', collapsible =TRUE, inverse=FALSE,
# define a message handler that will receive the variables on the client side
# from the server and update the page accordingly.
tags$head(tags$script("
Shiny.addCustomMessageHandler('updateSelections',
function(data) {
var nav_ref = '#page a:contains(\"' + data.nav + '\")';
var tabpanel_id = data.nav == 'Alpha' ? '#alpha_tabs' : '#beta_tabs';
var tab_ref = tabpanel_id + ' a:contains(\"' + data.tab + '\")';
$(nav_ref).tab('show');
$(tab_ref).tab('show');
}
)
")),
tabPanel('Alpha',
tabsetPanel(id='alph`a_tabs',
tabPanel('Tab')
)
),
tabPanel('Beta',
tabsetPanel(id='beta_tabs',
tabPanel('Golf'),
tabPanel('Hotel',
selectInput("beverage", "Choose a beverage:", choices = df_fil()$a),
selectInput("beverage1", "ch", choices = df_fil()$b)
)
)
)
)
server <- function(input, output, session) {
# df_fil <- function(){
# return(df %>% filter(a %in% input$beverage))
# }
observe({
data <- parseQueryString(session$clientData$url_search)
session$sendCustomMessage(type='updateSelections', data)
updateSelectInput(session, 'beverage', selected=data$beverage)
updateSelectInput(session, 'beverage1', selected=data$beverage1)
})
}
shinyApp(ui, server, enableBookmarking = "url")
fun.R
library(dplyr)
library(shiny)
source("app.R")
df <- data.frame(a = c("Tea", "Coffee", "Cocoa","Tea", "Coffee", "Cocoa"), b = c(1,2,3,4,5,6))
df_fil <- function(){
df[df$a == input$beverage,]
}