A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://appsilon.github.io/shiny.router/articles/basics.html below:

Introduction to the routing in Shiny with shiny.router • shiny.router

In this tutorial we will walk you through the basics of routing with the shiny.router library.

In a web application, routing is the process of using URLs to drive the user interface. Routing adds more possibilities and flexibility while building a complex and advanced web application, offering dividing app into separated sections.

Let’s build together a simple app that has two subpages and captures the data from url parameters.

We start by importing the packages.

Next, we create the content of our subpages: “home” and “another”.

home_page <- div(
  titlePanel("Home page"),
  p("This is the home page!"),
  uiOutput("power_of_input")
)

another_page <- div(
  titlePanel("Another page"),
  p("This is the another page!"),
)

Optionally, we can create a menu to easier navigate on our webapp:

menu <- tags$ul(
  tags$li(a(class = "item", href = route_link("/"), "Main")),
  tags$li(a(class = "item", href = route_link("another"), "Another page")),
)

Now, we create an output for our router in main UI of Shiny app. We also add sliderInput to test its functionality.

ui <- fluidPage(
  menu,
  tags$hr(),
  router_ui(
    route("/", home_page),
    route("another", another_page)
  ),
  sliderInput("int", "Choose integer:", -10, 10, 1, 1),
)

Then, we plug router into Shiny server (note: router_server() at the beginning).

In theory that would be it, but additionally we can also introduce the mechanism of catching the parameters from the URL. We will use get_query_param function. Our modified Server code may look like this:

It’s time to run it.

Here you can see the final result:

Feel free to copy the code of this example and test it on your own!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4