繁体   English   中英

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

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

所以,大约一个月前我正在做这个副项目,但后来因为我感到沮丧而放弃了它。 首先,我是闪亮和编程的新手,所以请保持温和:) 我有数据框,其中我每月有 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:我对最终产品的想法是,在左侧我们可以选择我们想要绘制的月份,而在右侧会有折线图,它将根据测量列绘制所选列,因此基本上图形将跟踪一个月内的温度行为。 如果可能的话,我想丢弃测量列并仅针对数据框索引绘制列。 正如我所说,我不知道前进的道路,一直在尝试很多方法,所以任何建议都值得赞赏!

输入列表中的对象从 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