1

我最近开始使用 R-Shiny,但我遇到了一个简单的问题,因此我被卡住了。

因此,我正在尝试构建一个反应式折线图,用户在其中定义数据库中的 2 个变量。

我已经能够获取下拉列表的变量列表,但我无法使用选定的值来绘制折线图。

参考代码:

library(shiny)

shinyUI(fluidPage(

# Application title
titlePanel("ARIMAX Forecasting Tool"),

sidebarLayout(
sidebarPanel(

...
mainPanel(
  tabsetPanel(type = "tabs", 
              tabPanel("Plot", plotOutput("plot")), 
              tabPanel("Summary")
  )
)
)
))

和部分服务器代码

shinyServer(function(input, output) {
output$plot <- renderPlot({
inFile <- input$file1

if (is.null(inFile))
  return(NULL)

content1=read.csv(inFile$datapath, header=input$header, sep=input$sep 
)
h=input$x
k=input$ts

plot(content1$k,content1$h,type="l")
})
})

我跳过了编写渲染 UI 以选择用户的部分variables.x,并且ts是用户为折线图选择的变量。

我在主面板区域收到错误:

需要有限的 xlim 值

4

1 回答 1

0

您必须包含一个可重现的示例 - 您的代码不会按原样运行。这对我来说是:

shinyApp(ui=
  shinyUI(fluidPage(
    titlePanel("Title"),
    sidebarPanel(sliderInput("number_points",label = "Number of points",min = 10,max = 1000,value = 100)),
    mainPanel(
      plotOutput("plot")
    )
  )
),
server=shinyServer(function(input, output) {
  output$plot <- renderPlot({
    plot(rnorm(input$number_points))
  })
})
)

此外,检查读取文件的代码并在闪亮的应用程序之外显示绘图工作。确实,错误消息表明那里有问题。

于 2014-06-15T12:52:37.853 回答