我正在基于表格构建一个简单的闪亮应用程序。 (最后是样本数据)。这是我最初的Server
设置:
更新:将reactive()
移到了function(input, output) {
内-但仍然出现空白图,但出现了Warning: Length of logical index must be 1 or 56, not 0
错误。
## Server ----
function(input, output) {
# Make data reactive
bet_data2 <- reactive(
{bet_data[bet_data$singleType == input$singleType &
bet_data$result == input$result, ]})
# Plot 1
output$plot1 <- renderPlot({
# Render first plot
print(
ggplot(bet_data2()) +
geom_bar(aes(result, fill = singleType),
position = position_dodge(), color = "black",
show.legend = T)
) +
theme_light()
)
})
}
这是UI
的设置:
## User Interface ----
daterange <- unique(bet_data$date)
team <- unique(bet_data$teamA)
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("TEST"),
# Generate a row with a sidebar
sidebarLayout(
selectInput("date", "Date:",
choices = daterange),
selectInput("team", "Team",
choices = team)
),
# Create a spot for the barplot
mainPanel(
plotOutput("plot1")
)
)
运行该应用程序时,我在应用程序窗口中得到Error: object 'input' not found
,在控制台中得到Error in [.tbl_df: object 'input' not found
。
我在做什么错?我认为我已经适当地进行了所有更改。
样本数据:
structure(list(date = structure(c(1548288000, 1548288000, 1548201600,
1548201600, 1548201600, 1547683200), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), singleBets = c("MTL/ARZ O6 (+120)", "CAR/VAN O5.5
(2u) (-120)",
"NYI Reg ML (+110)", "ARZ ML (-105)", "CGY/CAR O6.5 (-105)",
"NYR ML (+125)"), result = c("loss", "win", "loss", "win", "loss",
"win"), teamA = c("MTL", "CAR", "NYI", "ARZ", "CGY", "NYR"),
teamB = c("ARZ", "VAN", NA, NA, "CAR", NA), odds = c(120,
-120, 110, -105, -105, 125), singleType = c("over", "over",
"money-line", "money-line", "over", "money-line")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -6L), .Names = c("date",
"singleBets", "result", "teamA", "teamB", "odds", "singleType"
))