简体   繁体   English

如何从Shiny中的反应元素绘制列

[英]How to plot columns from reactive element in Shiny

This is my first app that I am making using Shiny, and I am having some trouble with my reactive plot. 这是我使用Shiny制作的第一个应用程序,我的反应式绘图遇到了一些麻烦。 My end goal is to be able to use the drop down menu to select client AD and then plot the datapoints from the columns (Date, ModResult) in a scatterplot when the Update button is pressed. 我的最终目标是能够使用下拉菜单选择客户端AD,然后在按下“更新”按钮时从散点图中的列(日期,ModResult)绘制数据点。 Right now it returns "Error in axis: no locations are finite." 现在,它返回“轴错误:没有位置是有限的”。 The labData data frame has 7 columns: "Client.Name" is column 1, "Date" is column 4, and "ModResult" is column 7. Please let me know if there is any more information that could help in debugging this error! labData数据框有7列:“ Client.Name”是第1列,“ Date”是第4列,“ ModResult”是第7列。请让我知道是否还有其他信息可以帮助调试此错误!

Thank you! 谢谢!

library(shiny)
ui <- fluidPage(titlePanel("Dilution History"),
  selectInput(inputId="client", label="Select Client Name", 
choices=levels(labData$Client.Name)), actionButton("update", "Update"), 
hr(),
  plotOutput("line")
)


server <- function(input, output, session){
#selected client into data frame
selDF <- reactive({data.frame(labData[labData[,1] =="input$client",])
  })   
  output$line <- renderPlot({
    plot(selDF()$Date, selDF()$ModResult, ylab="Result", main="Results 
For Client X Between Xdate and Ydate")
  })
}


shinyApp(ui = ui, server = server)

After few modifications 经过几次修改

library(shiny)
ui <- fluidPage(titlePanel("Dilution History"),
                selectInput(inputId = "client", label = "Select Client Name", 
                            choices = levels(labData$Clientname)), submitButton("update"), 
                hr(),
                plotOutput("line")
)


server <- function(input, output, session){

selDF <- reactive({data.frame(labData[labData$Clientname == input$client,])
  })
  output$line <- renderPlot({
    plot(selDF()$date, selDF()$result, ylab = "Result", main = "Results For Client X Between Xdate and Ydate")
  })
}

shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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