2017-12-03 179 views
0

我想从服务器反应性数据做一个情节。不幸的是,我无法得到工作的阴谋。我收到如下错误:“错误:EXPR必须是长度为1的矢量”。我尝试了不同样式的图表和不同的库:Quantmod,ggplot等等。有什么建议么?与来自服务器的反应性数据呼叫的闪亮应用程序

Server: 
library(shiny) 

Dat<-read.csv("A:\\home\\Documents\\Franchise_Failureby_Brand2011.csv", sep=';') 
names(Dat)[1]<-paste("Brand") 
names(Dat)[2]<-paste("Failure") 
names(Dat)[3]<-paste("Disbursement") 
names(Dat)[4]<-paste("Disb$X$1000") 
names(Dat)[5]<-paste("Chgoff") 
Dat1<-Dat[is.na(Dat)==FALSE,] 
Dat<-Dat1[1:578,] 

# Define server logic required to draw a histogram 
shinyServer(function(input, output) { 
    DatSv <- reactive({ 
    Value <- switch(input$Value, 
        "Failure"= Dat$Failure[1:10], 
        "Disbursement"=Dat$Disbursement[1:10], 
        "Disb$X$1000"=Dat$`Disb$X$1000`[1:10], 
        "Chgoff"=Dat$Chgoff[1:10]) 
    Brand<-Dat$Brand[1:10] 
    Brand(input$Value) 
    }) 

# Generate plot 
    output$plot1 <- renderPlot({ 
    library("quantmod") 
    hist(DatSv(), 
     main=paste('r', Value, '(', Brand, ')', sep='')) 
    }) 

    # Generate summary of data 

    output$summary<-renderPrint({ 
    summary(Dat) 
    }) 

}) 


UI: 
library(shiny) 
shinyUI(fluidPage(
    titlePanel("Plot Franchise Failure"), 
    sidebarLayout(
    sidebarPanel(
     radioButtons("n", "Chose output Y Axis:", 
        c("Failure" , 
        "Disbursement", 
        "Disb$X$1000" , 
        "Chgoff")), 

     checkboxInput("show_xlab", "Show/Hide X Axis Label", value=TRUE), 
     checkboxInput("show_ylab", "Show/Hide Y Axis Label", value=TRUE), 
     checkboxInput("show_title", "Show/Hide Title") 
    ), 
    mainPanel(
    tabsetPanel(
     type = "tabs", 
     tabPanel("Plot", plotOutput("plot1")), 
     tabPanel("Summary", verbatimTextOutput("summary")) 
) 
) 
) 
) 
) 
+1

你的问题可能来自交换机的声明。尝试在切换之前添加'req(input $ Value)'。 –

回答

0

嗨问题来自于将用户界面中的输入连接到服务器。在UI中,你已经为radioButton提供了inputid = "n"。这意味着我们可以通过input$n而不是input$Value获得Radibuttons的值。由于inputid = "Value"没有输入,因此后者始终为NULL。我的代码还有一些小问题,但这里是服务器代码的工作版本。我没有修改用户界面

library(shiny) 

Dat<-read.csv("A:\\home\\Documents\\Franchise_Failureby_Brand2011.csv", sep=';') 
names(Dat)[1]<-paste("Brand") 
names(Dat)[2]<-paste("Failure") 
names(Dat)[3]<-paste("Disbursement") 
names(Dat)[4]<-paste("Disb$X$1000") 
names(Dat)[5]<-paste("Chgoff") 
Dat1<-Dat[is.na(Dat)==FALSE,] 
Dat<-Dat1[1:578,] 

# Define server logic required to draw a histogram 
shinyServer(function(input, output) { 
    DatSv <- reactive({ 
    switch(input$n, 
      "Failure"= gsub("%","",as.character( Dat$Failure)), 
      "Disbursement"=Dat$Disbursement, 
      "Disb$X$1000"=gsub("\\$","",as.character( Dat$`Disb$X$1000`)), 
      "Chgoff"=gsub("%","",as.character(Dat$Chgoff))) 

    }) 

    # Generate plot 
    output$plot1 <- renderPlot({ 
    library("quantmod") 
    hist(as.numeric(DatSv()), 
     main=paste('Histogram of ',input$n, sep=''), 
     xlab = input$n) 
    }) 

    # Generate summary of data 

    output$summary<-renderPrint({ 
    summary(Dat) 
    }) 

}) 
相关问题