I am wanting to select values from 2 columns of a data frame using selectInput. I create the data frame using a file called KenPomeroyAnalysis.R. I store the data frame in a variable called pom.
library(XML)
library(dplyr)
# Parse Kenpom Data -------------------------------------------------------
pom <- "http://kenpom.com/" %>%
readHTMLTable() %>%
data.frame()
#columns to keep
vars <- c(2,5,6,8,10)
pom <- pom[,vars]
#change name of columns
names(pom) <- c("Team","Pyth","AdjO","AdjD","AdjT")
#make rows numeric
pom <- data.frame(pom$Team, sapply(pom[,c("Pyth","AdjO","AdjD","AdjT")], function(x) as.numeric(as.character(x))))
names(pom)[1] <- "Team"
#Delete rows with NAs
pom <- na.omit(pom)
#remove everything but the data set
rm(list=setdiff(ls(), "pom"))
I am wanting to create 2 different selectInput boxes for choosing pom$Team. The first selectInput is for selecting a "home_team" and the other for selecting a "away_team".
library(shiny)
#Define UI for application
shinyUI(fluidPage(
#Application Title
titlePanel("Ken Pomeroy Single Game Predictions"),
fluidRow(
selectInput("home_team",label="Home Team", choices=pom$Team),
selectInput("away_team",label="Away Team", choices=pom$Team)
),
mainPanel(
textOutput("text1")
)
))
My server.R file is where I am trying to run the KenPomeroyAnalysis.R file, so that I can have the pom data frame to interact with.
library(shiny)
source("KenPomeroyAnalysis.R")
shinyServer(function(input, output){
output$text1 <- renderText({
paste(input$home_team,"@",input$away_team)
})
})
However, when I try running the App, I get an Error saying:
ERROR: object 'pom' not found
This makes it seem like the server.R file is not first creating the data frame pom from the KenPomeroyAnalysis.R file. Any suggestions?
uiOutut()
on the UI side and generateselectInput()
on server side. – Gopala