【发布时间】:2015-02-12 21:36:53
【问题描述】:
我正在使用 Shiny 创建一个交互式应用程序。我想使用 ui.R 中的输入来过滤数据集,以便它将更改过滤数据集的输入的 xyplot。这是我的代码。
ui.R 是:
library(shiny) # load the shiny package
shinyUI(fluidPage(
titlePanel(h4('What makes a batter swing?', align = "center")),
sidebarPanel(
selectInput("PlateCount", label = "What is the count?",
choices = c("0-0" = '0-0', "0-1" = '0-1', "0-2" = '0-2', "0-3"='0-3'),
selected = '0-0'),
sliderInput("endspeed", "What is the Maximum end speed of the pitch?", min=38, max=95, value=50),
radioButtons("relief", label = "Relief Pitchers?",
choices = c("Relief", "Non-Relief",
"All Pitchers"), selected = "All Pitchers")
),
mainPanel(
plotOutput("plot")
)
)
)
我正在尝试使用 ggvis 或 xyplot 在马赛克中显示该图,但两者都出现错误消息。
library(shiny); library(dplyr); library(ggvis) # Load shiny package
Pitchers$count= as.character(Pitchers$count)
Pitchers$Swing <- as.character(Pitchers$Swing)
#here is trying mosaic
shinyServer(function(input, output){
plotData <- reactive({
df <- Pitchers %>%
filter(count==input$PlateCount)
})
output$plot <- renderPlot(xyplot(y~x, group=Swing, pch='.', data=df, auto.key=TRUE))
})
#here is trying ggvis
shinyServer(function(input, output){
plotData <- reactive({
df <- Pitchers %>%
filter(count==input$PlateCount)
})
output$plot <- renderUI(Pitchers %>%
ggvis(x = ~x, y = ~y) %>%
layer_points())
})
使用镶嵌选项时,会弹出错误消息,显示“'closure' 类型的'envir' 参数无效”。 使用 ggvis 选项,绘图显示在 RStudio 的绘图窗口中,但在应用程序中,我收到错误消息: 错误:参数长度为零
澄清一下,我并不是要同时创建两个情节,它们只是我试图制作情节的不同方式。我在运行应用程序时注释掉一个。
【问题讨论】:
-
output$plot <- renderPlot(xyplot(y~x, group=Swing, pch='.', data=df, auto.key=TRUE)),你的意思是写data=plotData()而不是data=df? -
也许你在ggvis版本中需要
filter_(~count==input$PlateCount)? -
第一条评论修复了xyplot命令,但是ggvis版本没有显示在应用程序中,它只显示在RStudio的绘图面板中。
-
@Megan,您能否提供一个可重现的数据集或指出您在哪里找到它(如果是公开的)?