Created
January 15, 2018 11:44
-
-
Save event15/fc7dca9e478357c9df67bda1c63a4157 to your computer and use it in GitHub Desktop.
Apka w R - shinydashboard
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
library(shiny) | |
library(shinydashboard) | |
library(tidyverse) | |
library(jsonlite) | |
library(DT) | |
library(plotly) | |
options(shiny.sanitize.errors = FALSE) | |
options(shiny.error=browser) | |
options(encoding = 'UTF-8') | |
options(tz="Europe/Warsaw") | |
source('global.R') | |
source("dashboard/linked_scatter.R") | |
source("dashboard/mostPopular.R") | |
sidebar <- dashboardSidebar( | |
sidebarMenu( | |
id = 'tabs', | |
menuItem('Dashboard', tabName = 'dashboard', icon = icon('dashboard')), | |
menuItem('Blog w liczbach', tabName = 'blogInNumbers', icon = icon('calculator')), | |
menuItem("Posty", tabName = 'posts', icon = icon('file-text')), | |
menuItem('Social Media', tabName = 'socialMedia', icon = icon('comments-o')), | |
menuItem( | |
'Charts', tabName = 'charts', icon = icon('bar-chart-o'), | |
menuSubItem('Subitem 1', tabName = 'subitem 1'), | |
menuSubItem('Subitem 2', tabName = 'subitem 2') | |
) | |
) | |
) | |
header <- dashboardHeader( | |
title = 'DMS Analytics' | |
) | |
body <- dashboardBody( | |
tabItems( | |
tabItem( | |
tabName = 'dashboard', | |
h2("Dashboard"), | |
fluidRow( | |
tabBox( | |
title = 'Najpopularniejsze', | |
id = 'mostpopular', | |
tabPanel( | |
'Kategorie', | |
mostPopularUI("prefix1") | |
), | |
tabPanel( | |
'Tagi', | |
'' | |
) | |
) | |
) | |
), | |
tabItem( | |
tabName = 'blogInNumbers', | |
fluidRow(h2('Blog w liczbach :)')), | |
h2("Module example") | |
), | |
tabItem( | |
tabName = 'posts', | |
fluidRow(h2('Widgets tab contentt')), | |
DT::dataTableOutput("mytable") | |
), | |
tabItem( | |
tabName = 'socialMedia', | |
fluidPage( | |
h3('The module creates two plots and a slider and is callet twice below') | |
#mostPopularUI('prefix1') | |
) | |
), | |
tabItem( | |
tabName = 'charts', | |
fluidRow(h2('Widgets tab content')) | |
), | |
tabItem( | |
tabName = 'widgets', | |
fluidRow(h2('Widgets tab content')) | |
), | |
tabItem( | |
tabName = 'widgets', | |
fluidRow(h2('Widgets tab content')) | |
) | |
) | |
) | |
ui <- dashboardPage(header, sidebar, body) | |
server <- function(input, output, session) { | |
json_data <- as.data.frame(getDataSet()) | |
output$mytable = DT::renderDataTable({ | |
json_data <- getDataSet() | |
}) | |
callModule(mostPopular, 'prefix1', 'json_data', json_data) | |
} | |
shinyApp(ui, server) |
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
library(shiny) | |
library(shinydashboard) | |
library(tidyverse) | |
library(jsonlite) | |
library(DT) | |
library(plotly) | |
#source('global.R') | |
# Most Popular UI | |
mostPopularUI <- function(id) { | |
ns <- NS(id) | |
list( | |
div(style="display: inline-block; height:220px;", plotOutput(ns("mtplot"))) | |
) | |
} | |
mostPopular <- function(input, output, session, my_data) { | |
output$mtplot <- renderPlot({ | |
trans_theme <- theme( | |
panel.grid.minor = element_blank(), | |
panel.grid.major = element_blank(), | |
panel.background = element_rect(fill = NA), | |
plot.background = element_rect(fill = NA), | |
plot.margin = unit(c(1, 1, 1, 1), "cm") | |
) | |
my_data %>% | |
count(categories) %>% | |
arrange(n) %>% | |
mutate(categories = factor(categories, levels = categories)) %>% | |
mutate(p = 100*n/sum(n)) %>% | |
ggplot() + | |
geom_col(aes(categories, n)) + | |
coord_flip() + | |
theme_bw() + trans_theme + labs(y = 'Liczba postów', x = '') | |
}) | |
} | |
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
library(tidyverse) | |
library(jsonlite) | |
getDataSet <- function() { | |
json_data <- fromJSON('data/data.json', flatten = TRUE) | |
json_data$categories <- as.character(json_data$categories) | |
json_data$tags <- as.character(json_data$tags) | |
json_data$comments_count <- as.integer(json_data$comments_count) | |
json_data$social.total <- as.integer(json_data$social.total) | |
json_data$social.facebok <- as.integer(json_data$social.facebok) | |
json_data$social.linkedin <- as.integer(json_data$social.linkedin) | |
json_data$social.google <- as.integer(json_data$social.google) | |
json_data$social.twitter <- as.integer(json_data$social.twitter) | |
json_data$social.pinterest <- as.integer(json_data$social.pinterest) | |
json_data$tags[which(json_data$tags=="character(0)")] <- "Nieotagowane" | |
social <- list( | |
facebook = json_data$social.facebok, | |
linkedin = json_data$social.linkedin, | |
twitter = json_data$social.twitter, | |
google = json_data$social.google, | |
pinterest = json_data$social.pinterest, | |
total = json_data$social.total | |
) | |
return(json_data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment