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