How do I get the Slider (name it for example "Divide mtcars wt") to popup for "option b" radio button, and divide x in aes (which is wt from mtcars datasets) of "option b" with that Slider Value in the reproducible example below? And then if "option a" radio button is selected, hide that Slider again. I have looked at several Stack overflow posts but they didn't help. I was keep getting NULL plot output error for "option b" when I implemented it so i took it out.
library(shiny)
library(ggplot2)
options(warn=-1)
#ui.r
ui <- pageWithSidebar(
headerPanel("many plots app"),
sidebarPanel(
sliderInput("width", "Plot Width (%)", min = 0, max = 100, value = 100),
sliderInput("height", "Plot Height (px)", min = 0, max = 800, value = 800),
uiOutput("filter_plot")
),
mainPanel(
uiOutput("plot")
)
)
#server.r
server <- function(input, output, session) {
options(warn = -1) #This doesn't stop console warning
output$filter_plot<-renderUI({
radioButtons("rd","Select Option",choices = c("a",
"b",
selected = "a"))
})
output$plot <- renderUI({
if(input$rd=="a"){
output$plot1<- renderPlot({
ggplot2::ggplot(mtcars, aes(mpg, cyl))+ geom_point()
})
plotOutput("plot1", width = paste0(input$width, "%"), height = input$height)
}
else if(input$rd=="b"){
output$plot2<- renderPlot({
ggplot2::ggplot(mtcars, aes(wt, qsec))+ geom_line()
})
plotOutput("plot2", width = paste0(input$width, "%"), height = input$height)
}
})
}
shinyApp(ui = ui, server = server)
Thank you in advance!
One more favour if you can, why are there warning in the console eventhough I have hidden them. My app works, but the warnings are there:
#Warning: Error in if: argument is of length zero
# 96: renderUI [C:/Users/YOU/Documents/DIRECTORY/xyz.R#443]
# 95: func
# 82: origRenderFunc
# 81: output$plot
# 1: runApp