Bellow is my shiny app. The idea here is when I click on switch button the chart appears (In this case the France chart).
I think the idea here is to have the switch input become the "principal" input once the user clikcs over it making the slider input have no effect. The slider input would only come "back to work" if the switch input turns off.
Bellow is my code:
library("shiny")
library("shinyWidgets")
library("gapminder")
library(tidyverse)
library(highcharter)
hc_data_1 <- gapminder %>% filter(country == 'Chile')
hc_data_2 <- gapminder %>% filter(country == 'Argentina')
hc_data_3 <- gapminder %>% filter(country == 'France')
country_list <- list(hc_data_1,hc_data_2,hc_data_3)
ui <- fluidPage(
sliderTextInput(inputId = "slider_new",
label = "Projections Range",
width = '100%',
choices = c('Chile','Chile-Argentina'),
selected = 'Chile-Argentina'
),
materialSwitch(
inputId ='swithc_slider',
label =tags$p("Switch"),
value =FALSE
),
htmlOutput('chart_1')
)
server <- function(input, output, session) {
output$chart_1<- renderUI({
if(input$slider_new == "Chile"){
gapminder %>% filter(country == 'Chile') %>% hchart(
"line",
hcaes(x = year, y = pop),
showInLegend = TRUE,
color = "#63696b",
name = "Title 1"
)
}else{
if(input$slider_new == "Chile-Argentina"){
hc_data_1 %>%
hchart(
"line",
hcaes(x = year, y = pop),
showInLegend = TRUE,
color = "#63696b",
name = "Title 1"
) %>%
hc_add_series(hc_data_2,
"spline",
color = "gray",
hcaes(x = year, y = pop),
showInLegend = TRUE)
}else{
gapminder %>% filter(country == 'France') %>% hchart(
"line",
hcaes(x = year, y = pop),
showInLegend = TRUE,
color = "#63696b",
name = "Title 1")
}
}
})
}
shinyApp(ui = ui, server = server)
So the idea is: once I click on the switch input the France chart appears. And independently of slider input position. And then to make the slider 'works' again I switch off and then the 'Chile' or 'Chile-Argentina' chart appears.