简体   繁体   English

R- Shiny:情节和用户选择之间的交互

[英]R- Shiny:interaction between plot and choices from user

So, I was doing this side project about month ago, but later dropped it as I was frustrated.所以,大约一个月前我正在做这个副项目,但后来因为我感到沮丧而放弃了它。 First, I'm new to shiny and programming so please, be gentle:) I have dataframe, in which I have temperatures for 20 days in month and columns represent months.首先,我是闪亮和编程的新手,所以请保持温和:) 我有数据框,其中我每月有 20 天的温度,列代表月份。 This part is OK, what comes net causes me much frustration.这部分还可以,网络带来的东西让我很沮丧。 Here is code:这是代码:

#mornings are column in dataframe that makes sure each month is excatly 20 measurements
Months <- c("J", "F", "Mar", "A", "May", "Jun", "Jul", "A", "S", "O", "N", "D")
library(ggplot2)
library(shiny)

ui <- fluidPage(
  titlePanel("Temperatures"),

  sidebarLayout(

    sidebarPanel(

           selectInput(inputId="day", label="DAY?", choices = Months)
  ),
   mainPanel(

      plotOutput("plot")
    )
  )
)

server <- function(input, output) {
  formulaText <- reactive({
    paste("Temperature: ", input$temp)
  })
  output$plot <- renderPlot({
    ggplot(data = rates) + geom_line(mapping = aes(x = mornings, y =     input$temp))
    })
}
shinyApp(ui, server)

IDEA: my idea of final product is that on left side we can choose which month we want to plot and on right side there will be line graph which will graph choosen column against measurements column, so basicly graph will track behavior of temperatures over month. IDEA:我对最终产品的想法是,在左侧我们可以选择我们想要绘制的月份,而在右侧会有折线图,它将根据测量列绘制所选列,因此基本上图形将跟踪一个月内的温度行为。 If it's possible I would like to throw measurement column out and plot only column against index of dataframe.如果可能的话,我想丢弃测量列并仅针对数据框索引绘制列。 As I said, I don't know path foward, been trying lots of thins, so any advice is appreciated!正如我所说,我不知道前进的道路,一直在尝试很多方法,所以任何建议都值得赞赏!

The Objects in the input list takes the names from inputId so combining the with the comment from Mike try changing you server code to this:输入列表中的对象从 inputId 中获取名称,因此将 与 Mike 的评论相结合,尝试将您的服务器代码更改为:

server <- function(input, output) {
  formulaText <- reactive({
    paste("Temperature: ", input$day)
  })
  output$plot <- renderPlot({
    ggplot(data = rates) + geom_line(mapping = aes_string(x = "mornings", y = input$day))
    })
}

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

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