图形不显示为闪亮[R]

图形不显示为闪亮[R],r,shiny,shinydashboard,R,Shiny,Shinydashboard,我正在使用R中的shiny package从用户那里获取输入,并将X和Y变量以线图的形式相互绘制。没有显示错误。除了图形之外,所有内容都显示出来。请有人帮助解释为什么不显示图形。这是ui.R文件 服务器.r 因此,在进一步检查后,您的脚本有两个问题: 输出$text4无法引用1 colm。这是因为范围界定 2当您注释掉输出$text4代码时,我现在在plot调用中收到一个未定义的列错误。这是因为强制列选择为数值返回NA 下面应该做你正在寻找的 以下是服务器.R代码: library(shiny)

我正在使用R中的shiny package从用户那里获取输入,并将X和Y变量以线图的形式相互绘制。没有显示错误。除了图形之外,所有内容都显示出来。请有人帮助解释为什么不显示图形。这是ui.R文件

服务器.r


因此,在进一步检查后,您的脚本有两个问题:

输出$text4无法引用1 colm。这是因为范围界定

2当您注释掉输出$text4代码时,我现在在plot调用中收到一个未定义的列错误。这是因为强制列选择为数值返回NA

下面应该做你正在寻找的

以下是服务器.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")})
})

因此,在进一步检查后,您的脚本有两个问题:

输出$text4无法引用1 colm。这是因为范围界定

2当您注释掉输出$text4代码时,我现在在plot调用中收到一个未定义的列错误。这是因为强制列选择为数值返回NA

下面应该做你正在寻找的

以下是服务器.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")})
})

您需要使用plot命令,而不是line命令。线用于添加到现有打印设备,而不是创建打印设备。plotdat[,colm],dat[,colm1],type=bI将line命令更改为plotdat[,colm],dat[,colm1],但仍然没有更改您想要直方图还是条形图?两个变量之间的线散点图用户选择您需要使用plot命令,而不是线。线用于添加到现有打印设备,而不是创建打印设备。plotdat[,colm],dat[,colm1],type=bI将line命令更改为plotdat[,colm],dat[,colm1],但仍然没有更改您想要直方图还是条形图?用户选择两个变量之间的线散点图
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")})
})
# 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")

)

)