---
title: "Getting Started"
author: "David Granjon & Veerle van Leemput"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Getting Started}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, echo=FALSE, message=FALSE}
library(bslib)
```
# Introduction
`{shinyMobile}` is built on top of the [Framework7](https://framework7.io) template (V8.3.3) and has different purposes:
- Develop __mobile-ready__ Shiny applications
- Turn your Shiny application into a __progressive web app__ (PWA)
Both with the goal of developing mobile apps that look and feel like native apps.
## Classic web apps, native apps and PWAs
Classic web apps are accessed via a browser and require an internet connection. They are built with HTML, CSS, and JavaScript. They are cross-platform and can be accessed from any device with a browser, which is convenient. This means they work on any mobile device! And your `shiny` app will also work perfectly fine on a mobile device. While this sounds nice, it doesn't give your users the most wonderful experience: a classic Shiny web app is not optimized for mobile devices. To name a few limitations:
- There's __no fullscreen__ option and the app is always displayed in a browser with the surrounding browser UI
- No consideration for __touch interfaces__
- Not optimized for __small screens__
- Can't be used when __offline__
So, what about native apps? Native apps are built for a specific platform (iOS or Android) and are installed on the device. They are developed with platform-specific languages (Swift for iOS, Kotlin for Android) and are distributed via the App Store, Google Play or other stores. Native apps are fast and responsive, and they can work offline. They can also access the device's hardware and software features (camera, GPS, etc.). However, they are expensive to develop and maintain: you need to know multiple languages and maintain multiple codebases.
Luckily, there is a middle ground: Progressive Web Apps (PWAs). PWAs are web applications that are regular web pages or websites, but can appear to the user like traditional applications or native mobile applications. They combine the best of both worlds: they can be __installed__ on the device, provide __offline__ features, can be __launched from the home screen__, and have a __fullscreen__ display. All with just one codebase!
Of course, turning your Shiny app into a PWA doesn't get you there completely: you also need UI components that are designed for touch interfaces and optimized for small screens- something Framework7 provides. It only makes sense to bring Framework7 and PWA capabilities to Shiny, and that's what `{shinyMobile}` does!
## Themes
`{shinyMobile}` offers 3 themes:
- __ios__
- __md__
- __auto__
When set to auto, it automatically detects if the app is running with Android (using Material Design, MD) or iOS and accordingly adapts the layout. It will use the MD theme for all other devices. It is of course possible to apply the iOS theme on an android device and inversely, although not recommended.
Besides these themes, `{shinyMobile}` gives you the possibility to choose between a light or dark mode, which can be set in the app options that we'll come back to later.
## Layouts
`{shinyMobile}` brings 4 out-of-the-box layouts:
- `f7SingleLayout()`: develop __simple__ apps (best choice for iOS/android Apps).
- `f7TabLayout()`: develop complex __multi-tabbed__ apps (best choice for iOS/android Apps).
- `f7SplitLayout()`: for __tablets__ with a sidebar, navbar and a main panel
- `f7MultiLayout()`: a layout consisting of __multiple pages__ that allows to have beautiful transitions between pages to provide a more native like experience. This layout is experimental.
## UI elements
With over 50 core components, `{shinyMobile}` provides a wide range of UI elements to build your app. These components are designed for mobile usage and provide a native app-like experience. They include inputs, containers, buttons, lists, modals, popups, and more. We'll pick a few to highlight here.
### Inputs: brief comparison side by side with `{shiny}`
`{shinyMobile}` has its own custom input widgets with unique design for each theme (iOS/android). Below we summarise all known shiny inputs and their equivalent with `{shinyMobile}`.
| Features (sample) | shiny | shinyMobile |
|----------|:-------------:|------:|
| Action button | `actionButton()` | `f7Button()` `f7Fab()`|
| Autocomplete | ❌ | `f7AutoComplete()` |
| Checkbox | `checkboxInput()`, `checkboxGroupInput()` | `f7Checkbox()`, `f7CheckboxGroup()`|
| Color | ❌ | `f7ColorPicker()`|
| Date | `dateInput()`, `dateRangeInput()` | `f7DatePicker()`|
| Download | `downloadButton()` | `f7DownloadButton()`|
| Numeric | `numericInput()` | `f7Stepper()` |
| Radio | `radioButtons()` | `f7Radio()` |
| Range slider | `sliderInput()` | `f7Slider()` |
| Select | `selectInput()` | `f7Select()`, `f7SmartSelect()`, `f7Picker()` |
| Stepper | ❌ | `f7Stepper()` |
| Text input | `textInput()`, `textAreaInput()` | `f7Text()`, `f7Password()`, `f7TextArea()` |
| Toggle switch | ❌ (see `{bslib}`) | `f7Toggle()` |
### Containers
`{shinyMobile}` provides a set of containers to organize the content of your app, including:
- `f7Accordion()`: an accordion container
- `f7Block()`: content block designed to add extra formatting and required spacing for text content
- `f7Card()`: a card container
- `f7List()`: a list container
- `f7Panel()`: sidebar elements
- `f7Popup()`: a popup window
- `f7Sheet()`: a modal sheet
- `f7Swiper()`: a swiper container (modern touch slider)
- `f7Tab()`: a tab container, to be used in combination with `f7Tabs()`
With these containers, you can organize your content in a way that makes sense for your app. Together with the layouts, you can create a wide variety of app designs for different purposes.
### Notifications & progress
There's also a set of components available to keep your users informed:
- `f7Dialog()`: a dialog window
- `f7Notif()`: a notification
- `f7Preloader()`: a preloader
- `f7Progressbar()`: a progress bar
- `f7Toast()`: a toast notification
These components can be used to provide feedback to the user, ask for input, or display information. The look and feel of these components are unique to the chosen theme (iOS/Android).
### Gallery
Curious to see a full-blown app built with `{shinyMobile}`? Check out our demo gallery! You can run the gallery with the following code:
```{r, eval=FALSE}
f7Gallery()
```
# Create your first App
## Page
Every `{shinyMobile}` app starts with a `f7Page()`.
```{r, eval=FALSE}
f7Page(
...,
options = list(...),
title = NULL,
allowPWA = FALSE
)
```
`f7Page()` accepts any of the following `{shinyMobile}` layouts: `f7SingleLayout()`, `f7TabLayout()`, `f7SplitLayout()` or the experimental `f7MultiLayout()`, which we will discuss further in the Layouts section.
The `options` sets up the app look and feel, and there's plenty of options to choose from, which we'll discuss below.
The `allowPWA` parameter allows you to add the necessary PWA dependencies to turn your app into a PWA.
## App options
This is where you can customize the global app behavior:
```{r, eval=FALSE}
options <- list(
theme = c("auto", "ios", "md"),
dark = TRUE,
skeletonsOnLoad = FALSE,
preloader = FALSE,
filled = FALSE,
color = "#007aff",
touch = list(
touchClicksDistanceThreshold = 5,
tapHold = TRUE,
tapHoldDelay = 750,
tapHoldPreventClicks = TRUE,
iosTouchRipple = FALSE,
mdTouchRipple = TRUE
),
iosTranslucentBars = FALSE,
navbar = list(
iosCenterTitle = TRUE,
hideOnPageScroll = TRUE
),
toolbar = list(
hideOnPageScroll = FALSE
),
pullToRefresh = FALSE
)
```
The default options are all set with the help of `f7DefaultOptions()`.
As stated above, you may choose between 3 themes (`md`, `ios` or `auto`) and there is support for a dark or light mode. The `dark` option supports 3 values: `TRUE`, `FALSE` or `"auto"`. In case of `"auto"`, the default, the app will automatically switch between dark and light mode based on the user's system settings.
The __color__ options simply changes the color of elements such as buttons, panel triggers, tabs triggers, and more. Note that the behaviour is different on the MD and iOS themes: in the MD theme the color gets "blended in" with the background, while in the iOS theme the color is more prominently visible in the elements. Another option to get more control over the colors in the app is using __filled__. It allows you to fill the navbar and toolbar with the chosen color if enabled.
__hideOnPageScroll__ allows to hide/show the navbar and toolbar which is useful to focus on the content. The __tapHold__ parameter ensure that the "long-press" feature is activated. __preloader__ is useful in case you want to display a loading screen.
Framework7 has many more [options](https://framework7.io/docs/app#app-parameters) which can be passed through this __options__ parameter- so you're not limited to the list above.
## Navbar
Before we dive into the different layouts, we'll take a look at components necessary for a layout- starting with the navbar. The __navbar__ is a mandatory element of any `{shinyMobile}` layout. It contains a title, a subtitle and triggers (if desired) for both right and left panels (`f7Panel()`).
```{r, eval=FALSE}
f7Navbar(
...,
subNavbar = NULL,
title = NULL,
hairline = TRUE,
bigger = FALSE,
transparent = FALSE,
leftPanel = FALSE,
rightPanel = FALSE
)
```
For complex apps, you can even add a sub-navbar with `f7SubNavbar(...)`, which may contain any element like `f7Button()` or text. `f7Navbar()` exposes styling parameters such as `hairline` (a subtle border), `bigger` (size of the navbar text) and `transparent`(for a transparent navbar).
## Toolbar
This is an option if you decide not to embed a `f7SubNavbar()` in the navbar, but still would like to have additional buttons or text. The toolbar is the right place to add things like `f7Button()`, `f7Link()` or `f7Badge()`. Its location is controlled with the position parameter (either top or bottom).
```{r, eval=FALSE}
f7Toolbar(
...,
position = c("top", "bottom"),
icons = FALSE,
scrollable = FALSE
)
```
Besides simply using `"top"` or `"bottom"`, you can also use different positions for iOS and MD themes by using: `"top-ios"`, `"top-md"`, `"bottom-ios"`, or `"bottom-md"`.
Under the hood, `f7Tabs()` is a custom `f7Toolbar()`.
## Panels
Panels are also called sidebars, `f7Panel()` being the corresponding function.
```{r, eval=FALSE}
f7Panel(
...,
id = NULL,
title = NULL,
side = c("left", "right"),
effect = c("reveal", "cover", "push", "floating"),
resizable = FALSE
)
```
`f7Panel()` can have different behaviors and this is controlled via the `effect` argument:
- __reveal__ makes the body content move and resize.
- __cover__ covers the body content.
- __floating___ makes the panel float over the body content.
- __push__ pushes the body content to the side.
The __resizable__ argument allows to dynamically resize the panel.
Note that for the moment, there is no option to control the width of each panel.
As stated previously for `f7SplitLayout()`, the `f7Panel()` may also be considered as a sidebar. In that case, we may include `f7PanelMenu()`. We'll get into more details about the split layout at the [dedicated section](#Split Layout).
## Layouts
`{shinyMobile}` offers four layouts:
- `f7SingleLayout()`
- `f7TabLayout()`
- `f7SplitLayout()`
- `f7MultiLayout()` (experimental)
The layout choice is crucial when you are developing an app. It depends on the complexity of your visualizations and content. If your plan is to develop a simple graph or table, you should go for the `f7SingleLayout()` option. For more complex design, the best is `f7TabLayout()`. `f7SplitLayout()` is specific for tablets apps.
### Single Layout
`f7SingleLayout()` is dedicated to build simple, one-page apps or gadgets.
```{r, eval=FALSE}
f7SingleLayout(
...,
navbar,
toolbar = NULL,
panels = NULL
)
```
Only the navbar is mandatory, other components such as the toolbar are optional for the `f7SingleLayout()`.
The app below runs with specific app options:
```{r, eval=FALSE}
f7Page(
options = list(
dark = FALSE,
filled = FALSE,
theme = "md"
),
...
)
```
```{r, eval=TRUE, echo=FALSE}
card(
shinyMobile:::create_app_link(
"NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRAVwhiLdIAoAdMAPQsAzgwEAbAJZ0BWCdIZQGATwHCAFpIjKAskTqTxcfgEpeEWo2ZbhpKOPF8IAAmf8NW3fsPG851wxwqETCzgC8zgR8YOqkpKjCiAICDFrkDABmUARwGADmkqTqLHQYkkQpaXCZ2XAAtNRQwjB1BIoQAqbmZhDmUoxKytwe2j39iirDmtp6BkZjCoPcaHAAHgTqSukLA5MAJqjiygw7E0N5eYdEpABMPeZ7UHbRcMQQRDCSBMIA+uIkeS6EFeJA+X1+-wgeWcAB46s4Qe9Pt8-gDnABSAB86P8zjyDE4qB+dCGADclJIoHR5hjsbjhFIctxuBBuCY6gBGAAMXJMiFZJnuvQgI2UAEF0E5XCxJOFnBkAOwABSgeTgUtcziIqFI5RFcqktm4jwYAGs5QAxMUAGQAygBRXDywxGPaWm0Op1FODwOX8GB7Uy4XGuXWkIx+sA6ZTONCofjBlyaxW2rR5IzWqDKTg8EOa6CkuhKOWKgByUELSm4YYjEX4qahEcz2ZYpCDedDRCI4iLDBLCoAKl2e1WO5rgsJCnrI3RrqQPgmx65FdatKbuOIqXBxJHVxBzRyE851IEMpHYvFEslqDf8l307liDB20nNcmFXv15u6Nvd2vnDcR4nnAZ51jEcQJEkAg3tQd5EA+GBPkCb6uCYiYoc4ADEzgwFAWiRCQ5BkGOioAMJKHsGoYTmUjAnKA5YAAqo6S7OIokjCHAboRAxzHoRhzh7JIpKSHs1T0UxLGvihNZwJG5EMG66hwFAYkMIu0lvis6ybAwpAAPKtqgrbREoKmkbpbZgD0GE2ZqdlofS1SkuJEQZGwBC6iQ3BaMZpBOjmfkmM4IB5oFrYACRmVAFlbLC8KBBAakSmsGxbNwoWabGqBrFRKGPHYcqImCKKQnk-EYaQyg5ZG0UaQJOFxmmcpQHAwh5RhqxygVcAVQJMYROS4gsHAXIcn1GEZC6crkqkVJGKxdlvsFWI4llrhQKsPzKJtHHGq8ki4eIwgAJIQBa-xPHKdy0uiWHOBALAwD+fZEGeYkEId9ihPOzimnAQSsZtPxpXpwx2AQ-3cc4vH2itdLrbGW07ase24V1EQACxel8ppihwXBypjS3OAAvnZpPdGApMALpAA", # nolint
"app",
header = FALSE
),
full_screen = TRUE,
style = "width: 393px; margin: 0 auto; float: none;"
)
```