1
我正试图做出一个非常简单的闪亮的应用程序,从曝光和控制组的在线广告的销售额中绘制置信区间。闪亮无法看到来自被动数据对象的数据帧
这里是我的代码: -
ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Easy Confidence Intervals for Proportions"),
# Sidebar with input for the number of trials
sidebarLayout(
sidebarPanel(
numericInput("exGrpSize", "Exposed Group Impressions", 10000),
numericInput("exGrpConv", "Exposed Group Clicks or Conversions", 100),
numericInput("contGrpSize", "Control Group Impressions", 10000),
numericInput("contGrpConv", "Control Group Clicks or Conversions", 100)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("intervalPlot")
)
)
))
server.R
library(shiny)
library(ggplot2)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# This is some very simple code to draw confidence intervals for proportions
# wrapped in a call to renderPlot to indicate that:
# 1) It is "reactive" and therefore should re-execute automatically when inputs change
# 2) Its output type is a plot
data <- reactive({
resp1 <- input$exGrpConv
size1 <- input$exGrpSize
resp2 <- input$contGrpConv
size2 <- input$contGrpSize
rate1 <- resp1/size1
rate2 <- resp2/size2
se1 <- 1.96*sqrt((1/size1)*rate1*(1-rate1))
se2 <- 1.96*sqrt((1/size2)*rate2*(1-rate2))
dataSet <- data.frame(
respVec = c(rate1, rate2),
group = factor(c("Exposed", "Control")),
se = c(se1, se2))
})
# # Define the top and bottom of the errorbars
limits <- aes(ymax = respVec + se, ymin = respVec - se)
#
output$intervalPlot <- renderPlot({
#
p <- ggplot(dataSet, aes(colour=group, y = respVec, x = group))
p + geom_point() + geom_errorbar(limits, width=0.2, lwd=2)
})
})
但是当我运行此我得到以下错误: -
Error in ggplot(dataSet, aes(colour = group, y = respVec, x = group)) : object 'dataSet' not found
如何从剧情的范围内的无功代码块中获取数据集?
[我知道在这里的置信区间是有点粗糙,这是最初的原型]
它还活着!非常感谢。 –
我很努力地理解什么类型的对象是data()对象,以及如何访问它的列...例如,如果我想要se2,我可以使用data()$ se2访问吗?它在ggplot中没有太多问题,因为'aes'可以让你自己引用列,但是'dygraphs'也可能需要列引用。 – d8aninja