n000b0
n000b0

Reputation: 21

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!

Upvotes: 2

Views: 115

Answers (1)

Bertil Baron
Bertil Baron

Reputation: 5003

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

Upvotes: 1

Related Questions