簡體   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