{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Wizualizacja danych (Lab 5)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "library(repr) # To resize plots in Jupyter\n", "options(repr.plot.width = 16, repr.plot.height = 9)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message:\n", "“package ‘ggplot2’ was built under R version 3.6.2”\n", "Warning message:\n", "“package ‘dplyr’ was built under R version 3.6.2”\n", "\n", "Attaching package: ‘dplyr’\n", "\n", "\n", "The following objects are masked from ‘package:stats’:\n", "\n", " filter, lag\n", "\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " intersect, setdiff, setequal, union\n", "\n", "\n" ] } ], "source": [ "library(shiny) # Main library\n", "library(ggplot2) # Plots\n", "library(dplyr) # Data manipulate\n", "library(babynames) # Data set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# shiny" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[*shiny*](https://shiny.rstudio.com/) to pakiet R, który ułatwia tworzenie wysoce interaktywnych aplikacji internetowych bezpośrednio w R. Korzystając z *shiny*, analitycy danych mogą tworzyć interaktywne aplikacje internetowe, które umożliwiają zespołowi zanurzenie się i eksplorowanie danych w postaci pulpitów nawigacyjnych (dashboard) lub wizualizacji.\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Podstawowa budowa aplikacji *shiny*\n", "\n", "library(shiny) # Load shiny library\n", "\n", "ui <- fluidPage() # Create the UI with a HTML\n", "\n", "server <- function(input, output, session) {} # Define a custom function to create the server\n", "\n", "shinyApp(ui = ui, server = server) # Run the app\n", "\n", "- Add inputs (UI)\n", "- Add outputs (UI/Server) \n", "- Update layout (UI)\n", "- Update outputs (Server)\n", "\n", "\n", "*shiny* zapewnia szeroką gamę danych wejściowych, które pozwalają użytkownikom zapewnić następujące dane:\n", "\n", "- tekst (*textInput, selectInput*), \n", "- liczby (*numericInput, sliderInput*), \n", "- wartośći logiczne (*checkBoxInput, radioInput*), \n", "- daty (*dateInput, dateRangeInput*).\n", "\n", "\n", "Wyjście:\n", "\n", "- *textOutput, renderText*, \n", "- *tableOutput, renderTable*,\n", "- *imageOutput, renderImage*,\n", "- *plotOutput, renderPlot*,\n", "- *DT::DTOutput(), DT::renderDT()* - interaktywne tabele." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ui <- fluidPage(\n", " textInput('name', 'What is your name?'), # Input \n", " textOutput('greeting') # Output\n", ")\n", "\n", "server <- function(input, output) {\n", " output$greeting <- renderText({ \n", " paste('Hello', input$name)\n", " })\n", "}\n", "\n", "shinyApp(ui = ui, server = server)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
year | sex | name | n | prop |
---|---|---|---|---|
<dbl> | <chr> | <chr> | <int> | <dbl> |
1880 | F | Mary | 7065 | 0.07238 |
1880 | F | Anna | 2604 | 0.02668 |
1880 | F | Emma | 2003 | 0.02052 |
1880 | F | Elizabeth | 1939 | 0.01987 |
1880 | F | Minnie | 1746 | 0.01789 |
1880 | F | Margaret | 1578 | 0.01617 |