Curating Your Data Science Content on RStudio Connect
This article is originally published at https://www.rstudio.com/blog/
RStudio Connect is RStudio’s publishing platform that hosts data science content created in R or Python, such as R Markdown documents, Shiny apps, Jupyter Notebooks, and more.
As you publish to RStudio Connect, you will want your audience to have a great experience looking through your work. Released in July 2021, the connectwidgets package helps create a custom view of your content. Your projects will be easier to organize, distribute, and discover.
The connectwidgets package queries your Connect server to get information about your published content items. It turns them into HTML widget components that can be displayed either in an R Markdown document or Shiny app.
The Marketing team at RStudio has several pieces of content published on RStudio’s Connect server. In this blog post, we’ll walk through how we created a project gallery using connectwidgets and R Markdown. View our gallery on colorado.rstudio.com!
Want to see connectwidgets in action? Check out Kelly O’Briant’s webinar, Build Your Ideal Showcase of Data Products.
Interested in trying out connectwidgets but don’t have RStudio Connect? Log into this evaluation environment to get access to a test server.
Curate Projects in R Markdown
Let’s begin by loading the connectwidgets package:
```{r}
install.packages("connectwidgets")
library(connectwidgets)
```
Open up a template by going to File, New File, R Markdown, From Template, and then selecting the connectwidgets(HTML)
example.
To establish the connection with your RStudio Connect server, add your credentials to your .Renviron
file:
CONNECT_SERVER="https://rsc.company.com/"
CONNECT_API_KEY="mysupersecretapikey"
In your R Markdown document, pull in your credential information with the function below:
```{r}
client <- connect(
# server = Sys.getenv("CONNECT_SERVER"),
# api_key = Sys.getenv("CONNECT_API_KEY")
)
```
The content()
function retrieves items from your RStudio Connect server and stores them in a tibble.
```{r}
all_content <- client %>%
content()
```
You can work with the resulting data frame using your usual R tools. For example, you can select items using built-in helper functions or the dplyr package. In this case, we want to filter the dataset to content by certain users:
```{r}
marketing_content <- all_content %>%
filter(owner_username %in% c("username1", "username2"))
```
Organize Your Work With HTML Widgets
The package provides organizational components for card, grid, and table views. Each component links to the associated content item in RStudio Connect.
For each chunk, you can select the components that you want to showcase.
Card View
Cards display your content and associated metadata. You can set the image and the description of your project from the RStudio Connect dashboard.
```{r card}
marketing_content %>%
filter(name == "specific_item_name") %>%
rsc_card()
```
Grid View
Grids allow you to place content in side-by-side tiles. Similar to cards, you can display certain pieces of metadata.
```{r grid-shiny}
marketing_content %>%
filter(app_mode == "shiny") %>%
rsc_grid()
```
Table View
Would you rather share text? The table component allows you to create a table that shows a fixed set of metadata.
```{r table-plumbertableau}
marketing_content %>%
filter(stringr::str_detect(name, "seattle_parking")) %>%
rsc_table()
```
Customize Your Data Science Gallery’s Look
Since connectwidgets is built on R Markdown, you can style your document’s colors and fonts. Here, we use the bslib package to customize our gallery’s appearance:
---
title: "RStudio Marketing Content Gallery"
output:
html_document:
theme:
bg: "#FFFFFF"
fg: "#404040"
primary: "#4D8DC9"
heading_font:
google: "Source Serif Pro"
base_font:
google: "Source Sans Pro"
code_font:
google: "JetBrains Mono"
---
Add narrative or additional code chunks to give context to your projects.
Publish to RStudio Connect for Easy Access
Once you’re ready, you can publish your document to RStudio Connect.
RStudio Connect allows you to update the access settings so that you can share your gallery with others. You can also create a custom vanity URL for your work.
Learn More
With RStudio Connect, you can publish your data science projects and also deliver a great experience to your audience.
- Learn more about RStudio Connect and connectwidgets.
- View Kelly O’Briant’s webinar, Build Your Ideal Showcase of Data Products, for an in-depth example of connectwidgets.
- Find out more about tracking the use of your RStudio Connect work by watching Cole Arendt’s presentation, Shiny Usage Tracking in RStudio Connect.
Thanks for visiting r-craft.org
This article is originally published at https://www.rstudio.com/blog/
Please visit source website for post related comments.