-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you demonstrate using this with htmlTemplate? #23
Comments
Hi @epspi , thanks for the idea. This could certainly be useful. We don't see fundamental reasons why this shouldn't work. PRs/PoC welcome, if you'd like to contribute an example :) |
@epspi here you find minimal example how to achieve this: library(shiny)
library(shiny.router)
options(shiny.router.debug = T)
# This generates menu in user interface with links.
menu <- (
tags$ul(
tags$li(a(class = "item", href = "/", "Page")),
tags$li(a(class = "item", href = route_link("other"), "Other page"))
)
)
# This creates UI for each page.
page <- function(title, content) {
div(
menu,
titlePanel(title),
p(content)
)
}
# Both sample pages.
root_page <- page("Home page", "Welcome on sample routing page!")
other_page <- page("Some other page", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
# Creates router. We provide routing path and UI for this page.
router <- make_router(
route("/", root_page),
route("other", other_page)
)
# Plug router into Shiny server.
server <- shinyServer(function(input, output, session) {
router(input, output, session)
output$url <- renderPrint(
get_query_param()
)
observeEvent(input$button, {
print("aaaa")
change_page("other?a=3&b=appsilon")
})
})
html_text = "
<!DOCTYPE html>
<html>
<head>
<script src=\"shared/jquery.js\" type=\"text/javascript\"></script>
<script src=\"shared/shiny.js\" type=\"text/javascript\"></script>
</head>
<body>
<h1>HTML UI</h1>
<div style=\"background-color:#fda97b\">
<div class=\"container-fluid\">
<div id=\"_router_ui\" class=\"shiny-html-output\"></div>
</div>
</div>
</body>
</html>
"
shinyApp(htmlTemplate(text_ = html_text), server) |
Closing. Feel free to reopen if needed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An important use case arises when you start with a set of html pages (e.g. a commercial theme for a cms, blog, shop, etc). As I see it, it would be preferable to use these html templates directly without rewriting the whole thing using tags$ wrappers. Any idea if the htmlTemplate approach is fundamentally incompatible with shiny.router, or is it possible for this to work?
The text was updated successfully, but these errors were encountered: