R- Shiny:用户

时间:2017-10-24 17:02:24

标签: r ggplot2 shiny

所以,我在一个月前做了这个侧面项目,但后来因为我感到沮丧而放弃了。 首先,我是新的闪亮和编程所以请,温柔:) 我有数据框,其中我的月份温度为20天,列数表示月份。这部分还可以,网来的东西让我很沮丧。这是代码:

#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:我对最终产品的想法是,在左侧我们可以选择我们想要绘制的月份,在右侧会有线图,它将根据测量列选择列,因此基本图表将跟踪温度的行为过了一个月。如果有可能我想抛出测量列并仅绘制数据帧索引列。正如我所说,我不知道路径,尝试了很多,所以任何建议都表示赞赏!

1 个答案:

答案 0 :(得分:1)

输入列表中的对象采用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))
    })
}