Dome
Dome

Reputation: 87

interactive table in Shiny R

I have this data frame:(Sites_daily_avg)

city_Name  day      wind         temperature   
London      1          1                   2                          
London      2          2                   2                         
London      3          3                   3                          
London      4          8                   9                          
....

I am trying to create a table providing a daily mean summary of all the weather variables for each site selected.

what I did;

fluidPage(
  titlePanel("Weather "),
  sidebarLayout(
    sidebarPanel(  
      selectizeInput("cities",
                     "city to compare",choices= Cities$City_Name)),
                     

mainPanel(
      tabsetPanel(
        tabPanel("City",
                 tableOutput(outputId = "daily_sum")                 
                 
        )

 )
    ) )
)
       



shinyServer(function(input, output) {
output$daily_sum <- renderTable({
    cityFilter <- subset(city_daily_avg, city_daily_avg$City_Name== input$City) %>%
      select(City_Name, day,  wind, temperature)})
  
})

Upvotes: 0

Views: 191

Answers (1)

akrun
akrun

Reputation: 887118

If there is more than one site selected, use %in% in the subset as == is elementwise operator and this can return unexpected TRUE/FALSE when the number of elements on the rhs of == is not 1 or the same length as the lhs

SiteFilter <- subset(Sites_daily_avg, Site_Name %in% input$sites)

If we neeed columns to be integer

shinyServer(function(input, output) {
output$daily_sum <- renderTable({
    SiteFilter <- subset(Sites_daily_avg, Site_Name %in% input$sites) %>%
      select(Site, Site_Name, day, air_temperature_mean, wind_speed_mean, rltv_hum_mean, visibility_mean) %>%
      mutate(across(c(Site, day), as.integer))
 })
  
})

Upvotes: 1

Related Questions