r - Shiny renderPlotly with two conditions -
i developing app in shiny. want render plot using submit button. want print labels if user check inputcheckbox. able render plot via button. doesnt work when checkbox checked.
here code:
library(shiny) library(plotly) ui <- fluidpage( actionbutton('run', 'run'), checkboxinput('printlab', 'label', false), plotlyoutput("plot1") ) server = function(input, output) { output$plot1 <- renderplotly({ req(input$run) isolate({ ggplotly(ggplot(data = mtcars, aes(wt, hp)) + geom_point(size=1, colour = "grey")) }) req(input$printlab) isolate({ ggplotly(ggplot(data = mtcars, aes(wt, hp)) + geom_point(size=1, colour = "grey") + geom_text(aes(label=wt), size=3, colour = "black")) }) }) } runapp(shinyapp(ui, server))
i'm no shiny expert, req(input$printlab)
doesn't right me. accomplish going for?
server <- function(input, output) { output$plot1 <- renderplotly({ req(input$run) if (!input$printlab) { ggplotly(ggplot(data = mtcars, aes(wt, hp)) + geom_point(size=1, colour = "grey")) } else { ggplotly(ggplot(data = mtcars, aes(wt, hp)) + geom_point(size=1, colour = "grey") + geom_text(aes(label=wt), size=3, colour = "black")) } }) }
(i'm sure there's better way. that's off top of head.)
Comments
Post a Comment