2016-01-04 2 views
1

Я использую блестящий пакет в R, чтобы принимать входные данные от пользователя и строить переменные X и Y друг против друга в качестве графика линии. Отображается ошибка. Все отображается, кроме graph.Please может кто-то помочь, почему граф не отображается .Здесь это файл ui.rГрафик не отображается блестящим [R]

library(shiny) # load the shiny package 
setwd("C:/indiahacks2") 
dat<-read.csv("final.csv") 

# Define UI for application 
shinyUI(fluidPage(

    # Header or title Panel 
    titlePanel(h4('Impulse Response on VAR MODEL', align = "center")), 

    # Sidebar panel 
    sidebarPanel(



    selectInput("Impulse", label = "1. Select the Impulse Variable", 
       choices = names(dat)), 
    selectInput("Response", label = "1. Select the Response Variable", 
       choices = names(dat)), 


    sliderInput("Lag", "2. Select the number of histogram BINs by using the slider below", min=0, max=25, value=10), 

    radioButtons("colour", label = "3. Select the color of histogram", 
       choices = c("Green", "Red", 
          "Yellow"), selected = "Green") 
), 

    # Main Panel 
    mainPanel(
    textOutput("text1"), 
    textOutput("text2"), 
    textOutput("text3"), 
    textOutput("text3"), 
    plotOutput("myhist") 

) 

) 
) 

Server.r

library(shiny) # Load shiny package 

dat<-read.csv("final.csv") 

shinyServer(


    function(input, output) { 

    output$text1 <- renderText({ 
     colm = as.numeric(input$Impulse) 
     paste("Impulse Variable is", names(dat[colm])) 

    }) 

    output$text2 <- renderText({ 
     paste("Color of plot is", input$radio) 
    }) 

    output$text3 <- renderText({ 
     paste("Number of Lags is", input$Lag) 
    }) 
    output$text4 <- renderText({ 
     colm = as.numeric(input$Response) 
     paste("Response Variable is", names(dat[colm])) 

    }) 

    output$myhist <- renderPlot(

     { 
     colm = as.numeric(input$Impulse) 
     colm1 = as.numeric(input$Response) 
     plot(dat[,colm],dat[,colm1])})  
}) 
+0

вы должны использовать 'plot' команду, а не строки. 'lines' используется для добавления к существующему сюжетному устройству, а не к созданию. 'plot (dat [, colm], dat [, colm1], type =" b ")' – emilliman5

+0

Я изменил команду линии на график (dat [, colm], dat [, colm1]), но все равно никаких изменений –

+0

вы хотите гистограмму или гистограмму? – MLavoie

ответ

3

Так есть несколько вещей, не так с вашим сценарий, при дальнейшем осмотре:

1) colm не может ссылаться на output$text4. Это связано с тем, что ...

2) Когда вы закомментируете код output$text4, теперь я получаю неопределенную ошибку столбца в вызове plot. Это связано с тем, что для выбора столбцов числовые значения возвращаются NA.

Ниже следует делать то, что вы ищете.

Вот код server.R:

library(shiny) # Load shiny package 
dat<-read.csv("final.csv") 

shinyServer(

function(input, output) { 

    output$text1 <- renderText({ 
     colm = as.numeric(input$Impulse) 
     paste("Impulse Variable is", columns()[2]) 

    }) 
    output$text2 <- renderText({ 
     paste("Color of plot is", input$radio) 
    }) 

    output$text3 <- renderText({ 
     paste("Number of Lags is", input$Lag) 
    }) 
    output$text4 <- renderText({ 
     colm = as.numeric(input$Response) 
     paste("Response Variable is", columns()[2]) 

    }) 

    columns<-reactive({ 
     colm = as.character(input$Impulse) 
     colm1 = as.character(input$Response) 
     return(c(colm, colm1)) 
    }) 

    output$myhist <- renderPlot(

     { 
      plot(dat[,columns()[1]],dat[,columns()[2]],type="b")}) 
}) 

* Ui.R

# Define UI for application 
library(shiny) 
shinyUI(fluidPage(

# Header or title Panel 
titlePanel(h4('Impulse Response on VAR MODEL', align = "center")), 

# Sidebar panel 
sidebarPanel(



    selectInput("Impulse", label = "1. Select the Impulse Variable", 
       choices = names(dat)), 
    selectInput("Response", label = "1. Select the Response Variable", 
       choices = names(dat)), 


    sliderInput("Lag", "2. Select the number of histogram BINs by using the slider below", min=0, max=25, value=10), 

    radioButtons("colour", label = "3. Select the color of histogram", 
       choices = c("Green", "Red", 
          "Yellow"), selected = "Green") 
), 

# Main Panel 
mainPanel(
    textOutput("text1"), 
    textOutput("text2"), 
    textOutput("text3"), 
    textOutput("text4"), 
    plotOutput("myhist") 

) 

) 
Смежные вопросы