Bhaskar Mitra
2020-Nov-17 02:18 UTC
[R] Request for help to modify sliderInput in RShiny app (conditional statement)
Hello Everyone, I have written certain codes in RShiny app which works fine. There are 3 tabs, "Z1", "Z2" and "Z3". Currently the sliderinput shows up when I click all the 3 tabs. I need to adjust this code so that sliderInput is only visible when i click tab "Z1" and not for tabs "Z2" and "Z3". Can anyone please suggest how to modify the codes in that regard? the codes for ui.r and server.r are given below. thanks for your help, regards, bhaskar #################################################################################### #Codes for ui.r library(shiny) library(shinydashboard) library(shinyjs) fluidPage( sidebarLayout(position = "left", sidebarPanel( sliderInput(inputId = "year", label = "Years included", min = 1990, max = 2000, value = c(1990, 2000), sep = "", step = 1), column(width = 10, plotOutput("distPlot")) ), mainPanel( tabsetPanel(type = "pills", position = "below", tabPanel("Z1", plotOutput("trend")), tabPanel("Z2", plotOutput("trend1")), tabPanel("Z3", plotOutput("trend2")) ), ) ) ) ############################################################################################ #Codes for server.r #library(ggthemes) library(gapminder) library(leaflet) library(ggmap) library(tidyverse) library(lubridate) library(fpp2) library(zoo) library(shinydashboard) library(shinyjs) library(ggpubr) df7 = read_csv("data.csv") df8 = read_csv("data1.csv") function(input, output) { theData = reactive({ df7 %>% filter(year >= input$year[1], year <= input$year[2]) }) theData1 = reactive({df8}) output$trend = renderPlot ({ lp1 <- theData() %>% gather(metric, value, x1) %>% ggplot(aes(date, value, color = metric)) + geom_line() print(lp1) }) output$trend1 = renderPlot ({ lp2 <- theData1() %>% gather(metric, value, x2) %>% ggplot(aes(date, value, color = metric)) + geom_line() print(lp2) }) output$trend2 = renderPlot ({ lp3 <- theData1() %>% gather(metric, value, x3) %>% ggplot(aes(date, value, color = metric)) + geom_line() print(lp3) }) } [[alternative HTML version deleted]]