简体   繁体   中英

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. 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. 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:

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))
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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