简体   繁体   中英

R Shiny Reactive plot using user selected variable

I have recently started using R-Shiny and I have a simple problem due to which I am stuck.

So, I am trying to build a reactive line chart where the user defines the 2 variables from the database.

I have been able to get the variable lists for the drop down but I am not able to use the selected value to plot the line chart.

Refer to the code:

library(shiny)

shinyUI(fluidPage(

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

sidebarLayout(
sidebarPanel(

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

and the partial server code

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")
})
})

I have skipped the part where I write the render UI to get the user selected variables.x and ts are the variable selected by the user for the line chart.

I get an error in the main panel area:

need finite xlim values

You have to include a reproducible example- your code does not run as is. This runs for me:

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))
  })
})
)

Also, check the code reading the file and displaying the plot works outside the shiny app. Indeed the error message suggests something is wrong there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM