Skip to content
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

Closed
epspi opened this issue Oct 19, 2017 · 3 comments
Closed

Can you demonstrate using this with htmlTemplate? #23

epspi opened this issue Oct 19, 2017 · 3 comments

Comments

@epspi
Copy link

epspi commented Oct 19, 2017

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?

@marekrogala
Copy link

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 :)

@dokato
Copy link
Contributor

dokato commented Feb 16, 2018

@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)

@dokato
Copy link
Contributor

dokato commented Jun 7, 2018

Closing. Feel free to reopen if needed.

@dokato dokato closed this as completed Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants