Skip to content

Instantly share code, notes, and snippets.

@rfaelens
Created January 17, 2020 10:49
Show Gist options
  • Save rfaelens/a37898ec1614a0751fbd0a763d25dc59 to your computer and use it in GitHub Desktop.
Save rfaelens/a37898ec1614a0751fbd0a763d25dc59 to your computer and use it in GitHub Desktop.
library(plotly)
library(ggplot2)
ui <- fluidPage(
column(6,
checkboxInput("go_table", label="Render table", value=TRUE),
tableOutput("table")
),
column(6,
checkboxInput("go_plot", label="Render plot", value=TRUE),
plotlyOutput("plot")
)
)
server <- function(input, output, session) {
output$table <- snapshotPreprocessOutput(
renderTable({
shiny::req(input$go_table) #induce a silent.error if input$go is FALSE
data.frame(x=rnorm(5), y=runif(5))
}), function(x) {
XML::readHTMLTable(x) #snapshot as table contents
})
output$plot <- renderPlotly({
shiny::req(input$go_plot) #induce a silent.error if input$go is FALSE
ggplot(data.frame(x=rnorm(1000))) +
geom_histogram(aes(x=x))
})
}
shinyApp(ui=ui, server=server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment