-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"name":"app.R","content":"library(shiny)\r\nlibrary(dplyr)\r\nlibrary(htmltools)\r\nlibrary(glue)\r\nlibrary(rlang)\r\nlibrary(shinythemes)\r\n\r\n# Data\r\nload(url(\"https://raw.githubusercontent.com/nrennie/tidytuesday-shiny-app/main/data/all_weeks.RData\"))\r\nall_titles <- all_weeks$title\r\nall_pkgs <- dplyr::select(all_weeks, -c(year, week, title, pkgs, code_fpath, img_fpath))\r\nall_pkgs <- colnames(all_pkgs)\r\n\r\n# Define UI for app that draws a histogram ----\r\nui <- fluidPage(\r\n\r\n theme = shinytheme(\"superhero\"),\r\n\r\n titlePanel(\"#TidyTuesday\"),\r\n\r\n sidebarLayout(\r\n\r\n sidebarPanel(\r\n markdown(\"[Nicola Rennie](https://github.com/nrennie)\r\n\r\n#TidyTuesday is a weekly data challenge aimed at the R community. Every week a new dataset is posted alongside a chart or article related to that dataset, and ask participants explore the data. You can access the data and find out more on [GitHub](https://github.com/rfordatascience/tidytuesday/blob/master/README.md).\r\n\r\nMy contributions can be found on [GitHub](https://github.com/nrennie/tidytuesday), and you can use this Shiny app to explore my visualisations with links to code for each individual plot. You can also follow my attempts on Mastodon at [fosstodon.org/@nrennie](https://fosstodon.org/@nrennie).\r\n\"),\r\nhtmltools::hr(),\r\nhtmltools::tags$details(\r\n htmltools::tags$summary(\"Filter R packages (click to expand):\"),\r\n shiny::radioButtons(\"pkg_select\",\r\n \"Only show plots that use:\",\r\n choices = c(\"Any package\", all_pkgs),\r\n selected = NULL,\r\n inline = TRUE\r\n )\r\n),\r\n# choose a plot\r\nshiny::uiOutput(\"select_img\"),\r\n# display information\r\nshiny::textOutput(\"pkgs_used\"),\r\nhtmltools::br(),\r\nshiny::htmlOutput(\"code_link\"),\r\nhtmltools::br(),\r\nshiny::htmlOutput(\"r4ds_link\"),\r\nhtmltools::br(),\r\nwidth = 6\r\n ),\r\n\r\nmainPanel(\r\n shiny::htmlOutput(\"plot_img\"),\r\n htmltools::br(),\r\n width = 6\r\n)\r\n )\r\n)\r\n\r\nserver <- function(input, output) {\r\n # Get data\r\n all_titles <- reactive({\r\n req(input$pkg_select)\r\n if (input$pkg_select == \"Any package\") {\r\n all_titles <- all_weeks$title\r\n } else {\r\n all_titles <- all_weeks %>%\r\n dplyr::filter(!!rlang::sym(input$pkg_select) == 1) %>%\r\n dplyr::pull(title)\r\n }\r\n })\r\n\r\n # Select title\r\n output$select_img <- renderUI({\r\n shiny::selectInput(\"plot_title\",\r\n \"Select a plot:\",\r\n choices = rev(all_titles()),\r\n width = \"90%\"\r\n )\r\n })\r\n\r\n # Get data\r\n week_data <- reactive({\r\n req(input$plot_title)\r\n dplyr::filter(all_weeks, title == input$plot_title)\r\n })\r\n\r\n ## Image display\r\n img_path <- shiny::reactive({\r\n glue::glue(\"https://raw.githubusercontent.com/nrennie/tidytuesday/main/{week_data()$img_fpath}\")\r\n })\r\n\r\n output$plot_img <- shiny::renderText({\r\n c('<img src=\"', img_path(), '\" width=\"100%\">')\r\n })\r\n\r\n ### List of packages\r\n output$pkgs_used <- shiny::renderText({\r\n glue::glue(\r\n \"This plot uses the following packages: {week_data()$pkgs}\"\r\n )\r\n })\r\n\r\n ### Code link\r\n code_path <- shiny::reactive({\r\n glue::glue(\r\n \"https://github.com/nrennie/tidytuesday/tree/main/{week_data()$code_fpath}\"\r\n )\r\n })\r\n\r\n output$code_link <- shiny::renderText({\r\n glue::glue(\r\n '<b>Code is available at<\/b>: <a href=\"{code_path()}\" target=\"_blank\">{code_path()}<\/a>.'\r\n )\r\n })\r\n\r\n ### R4DS link\r\n r4ds_path <- shiny::reactive({\r\n if (week_data()$year == \"2021\") {\r\n reformat_week <- as.character(as.Date(week_data()$week, format = \"%d-%m-%Y\"))\r\n glue::glue(\r\n \"https://github.com/rfordatascience/tidytuesday/blob/master/data/{week_data()$year}/{reformat_week}/readme.md\"\r\n )\r\n } else {\r\n glue::glue(\r\n \"https://github.com/rfordatascience/tidytuesday/blob/master/data/{week_data()$year}/{week_data()$week}/readme.md\"\r\n )\r\n }\r\n })\r\n\r\n output$r4ds_link <- shiny::renderText({\r\n glue::glue('<b>R4DS GitHub link<\/b>: <a href=\"{r4ds_path()}\" target=\"_blank\">{r4ds_path()}<\/a>.')\r\n })\r\n}\r\n\r\nshinyApp(ui = ui, server = server)\r\n","type":"text"}] | ||
[{"name":"app.R","content":"library(shiny)\r\nlibrary(dplyr)\r\nlibrary(htmltools)\r\nlibrary(glue)\r\nlibrary(rlang)\r\nlibrary(shinythemes)\r\n\r\n# Data\r\nload(url(\"https://raw.githubusercontent.com/nrennie/tidytuesday/main/data/all_weeks.RData\"))\r\nall_titles <- all_weeks$title\r\nall_pkgs <- dplyr::select(all_weeks, -c(year, week, title, pkgs, code_fpath, img_fpath))\r\nall_pkgs <- colnames(all_pkgs)\r\n\r\n# Define UI for app that draws a histogram ----\r\nui <- fluidPage(\r\n\r\n theme = shinytheme(\"superhero\"),\r\n\r\n titlePanel(\"#TidyTuesday\"),\r\n\r\n sidebarLayout(\r\n\r\n sidebarPanel(\r\n markdown(\"[Nicola Rennie](https://github.com/nrennie)\r\n\r\n#TidyTuesday is a weekly data challenge aimed at the R community. Every week a new dataset is posted alongside a chart or article related to that dataset, and ask participants explore the data. You can access the data and find out more on [GitHub](https://github.com/rfordatascience/tidytuesday/blob/master/README.md).\r\n\r\nMy contributions can be found on [GitHub](https://github.com/nrennie/tidytuesday), and you can use this Shiny app to explore my visualisations with links to code for each individual plot. You can also follow my attempts on Mastodon at [fosstodon.org/@nrennie](https://fosstodon.org/@nrennie).\r\n\"),\r\nhtmltools::hr(),\r\nhtmltools::tags$details(\r\n htmltools::tags$summary(\"Filter R packages (click to expand):\"),\r\n shiny::radioButtons(\"pkg_select\",\r\n \"Only show plots that use:\",\r\n choices = c(\"Any package\", all_pkgs),\r\n selected = NULL,\r\n inline = TRUE\r\n )\r\n),\r\n# choose a plot\r\nshiny::uiOutput(\"select_img\"),\r\n# display information\r\nshiny::textOutput(\"pkgs_used\"),\r\nhtmltools::br(),\r\nshiny::htmlOutput(\"code_link\"),\r\nhtmltools::br(),\r\nshiny::htmlOutput(\"r4ds_link\"),\r\nhtmltools::br(),\r\nwidth = 6\r\n ),\r\n\r\nmainPanel(\r\n shiny::htmlOutput(\"plot_img\"),\r\n htmltools::br(),\r\n width = 6\r\n)\r\n )\r\n)\r\n\r\nserver <- function(input, output) {\r\n # Get data\r\n all_titles <- reactive({\r\n req(input$pkg_select)\r\n if (input$pkg_select == \"Any package\") {\r\n all_titles <- all_weeks$title\r\n } else {\r\n all_titles <- all_weeks %>%\r\n dplyr::filter(!!rlang::sym(input$pkg_select) == 1) %>%\r\n dplyr::pull(title)\r\n }\r\n })\r\n\r\n # Select title\r\n output$select_img <- renderUI({\r\n shiny::selectInput(\"plot_title\",\r\n \"Select a plot:\",\r\n choices = rev(all_titles()),\r\n width = \"90%\"\r\n )\r\n })\r\n\r\n # Get data\r\n week_data <- reactive({\r\n req(input$plot_title)\r\n dplyr::filter(all_weeks, title == input$plot_title)\r\n })\r\n\r\n ## Image display\r\n img_path <- shiny::reactive({\r\n glue::glue(\"https://raw.githubusercontent.com/nrennie/tidytuesday/main/{week_data()$img_fpath}\")\r\n })\r\n\r\n output$plot_img <- shiny::renderText({\r\n c('<img src=\"', img_path(), '\" width=\"100%\">')\r\n })\r\n\r\n ### List of packages\r\n output$pkgs_used <- shiny::renderText({\r\n glue::glue(\r\n \"This plot uses the following packages: {week_data()$pkgs}\"\r\n )\r\n })\r\n\r\n ### Code link\r\n code_path <- shiny::reactive({\r\n glue::glue(\r\n \"https://github.com/nrennie/tidytuesday/tree/main/{week_data()$code_fpath}\"\r\n )\r\n })\r\n\r\n output$code_link <- shiny::renderText({\r\n glue::glue(\r\n '<b>Code is available at<\/b>: <a href=\"{code_path()}\" target=\"_blank\">{code_path()}<\/a>.'\r\n )\r\n })\r\n\r\n ### R4DS link\r\n r4ds_path <- shiny::reactive({\r\n if (week_data()$year == \"2021\") {\r\n reformat_week <- as.character(as.Date(week_data()$week, format = \"%d-%m-%Y\"))\r\n glue::glue(\r\n \"https://github.com/rfordatascience/tidytuesday/blob/master/data/{week_data()$year}/{reformat_week}/readme.md\"\r\n )\r\n } else {\r\n glue::glue(\r\n \"https://github.com/rfordatascience/tidytuesday/blob/master/data/{week_data()$year}/{week_data()$week}/readme.md\"\r\n )\r\n }\r\n })\r\n\r\n output$r4ds_link <- shiny::renderText({\r\n glue::glue('<b>R4DS GitHub link<\/b>: <a href=\"{r4ds_path()}\" target=\"_blank\">{r4ds_path()}<\/a>.')\r\n })\r\n}\r\n\r\nshinyApp(ui = ui, server = server)\r\n","type":"text"}] |