Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Created June 16, 2020 18:03
Show Gist options
  • Save gadenbuie/e933c19b602979158e8e86d63fd66dbd to your computer and use it in GitHub Desktop.
Save gadenbuie/e933c19b602979158e8e86d63fd66dbd to your computer and use it in GitHub Desktop.
library(shiny)
# remotes::install_github("gadenbuie/epoxy@shiny-inline-inputs")
library(epoxy)
# Module ------------------------------------------------------------------
epoxyModTestUI <- function(id) {
ns <- NS(id)
tagList(
h2("Is it rainy there?"),
epoxyHTML(
.id = ns("demo"),
.watch = list(click = "city"),
"<p>If you lived in {{city}}, ",
"you'd see an average of {{rain}} inches of rain each year.</p>"
),
tags$style(
# not necessary, just looks cool
'[data-epoxy-input-click]:hover { background-color: #fcf0cb; }'
)
)
}
epoxyModTest <- function(input, output, session, ...) {
city <- reactive({
input$demo_city_clicked
sample(names(precip), 1)
})
output$demo <- renderEpoxyHTML(
city = city(),
rain = precip[city()]
)
}
# App ---------------------------------------------------------------------
ui <- fluidPage(
epoxyModTestUI("test")
)
server <- function(input, output, session) {
callModule(epoxyModTest, "test")
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment