0
我想要使用selectInput從數據框的2列中選擇值。我使用名爲KenPomeroyAnalysis.R的文件創建數據框。我將數據框存儲在一個名爲pom的變量中。使用Shiny App從數據框中選擇
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"))
我想創建2個不同的selectInput框來選擇pom $ Team。第一個selectInput用於選擇「home_team」,另一個用於選擇「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")
)
))
我server.R文件是我試圖運行KenPomeroyAnalysis.R文件,這樣我可以有POM數據幀進行交互。
library(shiny)
source("KenPomeroyAnalysis.R")
shinyServer(function(input, output){
output$text1 <- renderText({
paste(input$home_team,"@",input$away_team)
})
})
然而,當我嘗試運行應用程序,我得到一個錯誤說:
ERROR: object 'pom' not found
這使得它看起來像server.R文件不首先創建從KenPomeroyAnalysis數據幀POM .R文件。有什麼建議麼?
這是...但是,這將不會在UI腳本中看到,因爲名稱空間將不同。一種選擇是在UI端使用'uiOutut()'並在服務器端生成'selectInput()'。 – Gopala