-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
797dd2b
commit 865aba6
Showing
3 changed files
with
132 additions
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
library(shiny) | ||
library(tidyverse) | ||
library(ggraph) | ||
library(tidygraph) | ||
|
||
|
||
|
||
# Define UI for application | ||
ui <- fluidPage( | ||
|
||
# Application title | ||
titlePanel("Social Network"), | ||
|
||
# Sidebar with a slider input for number of bins | ||
sidebarLayout( | ||
sidebarPanel( | ||
sliderInput("radius", | ||
"Node radius", | ||
min = 1, | ||
max = 50, | ||
value = 30), | ||
|
||
selectInput("style","Layout",c("dendrogram","stress","circlepack")) | ||
), | ||
|
||
# Show outputs | ||
mainPanel( | ||
plotOutput("graphPlot",width = "600px"), | ||
textOutput("description") | ||
) | ||
) | ||
) | ||
|
||
|
||
server <- function(input, output) { | ||
|
||
# load data | ||
graph <- as_tbl_graph(highschool) | ||
|
||
output$graphPlot <- renderPlot({ | ||
|
||
ggraph(graph(), layout = "dendrogram") + | ||
geom_edge_link() + | ||
geom_node_circle(aes(r=input$radius/100.0),fill="black")+ | ||
ggraph::theme_graph() | ||
|
||
}) | ||
} | ||
|
||
# Run the application | ||
shinyApp(ui = ui, server = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
library(shiny) | ||
library(dplyr) | ||
library(ggplot2) | ||
|
||
# Define UI for application that draws a histogram | ||
ui <- fluidPage( | ||
|
||
# Application title | ||
titlePanel("Is this normal?"), | ||
|
||
fluidRow( | ||
column(12, | ||
numericInput(inputId="n",label = "Sample size",value=100,min=5,max=100), | ||
plotOutput(outputId = "result"), | ||
shiny::actionButton(inputId = "yes", label="Yes"), | ||
shiny::actionButton(inputId = "no", label="No"), | ||
htmlOutput(outputId = "msg") | ||
) | ||
) | ||
|
||
|
||
) | ||
|
||
|
||
server <- function(input, output) { | ||
|
||
|
||
values <- reactiveValues(normal = 1, status = "") | ||
|
||
observe({ | ||
input$yes | ||
cat("YES\n") | ||
check(TRUE) | ||
}) | ||
|
||
observe({ | ||
input$no | ||
cat("NO\n") | ||
check(FALSE) | ||
}) | ||
|
||
check <- function(user_choice) { | ||
if (user_choice == values$normal) { | ||
values$status <- "<p style='color:green;'>CORRECT!</p>" | ||
} else { | ||
values$status <- "<p style='color:red;'>WRONG!</p>" | ||
} | ||
|
||
values$normal <- sample(c(TRUE,FALSE),1) | ||
|
||
} | ||
|
||
output$result <- renderPlot({ | ||
|
||
|
||
if ( values$normal ) { | ||
dat<-rnorm(input$n) | ||
} else { | ||
type = sample(c(1,2,3),1) | ||
if (type==1) { | ||
dat<-rchisq(input$n,df = 3)-1 | ||
} else if (type==2) { | ||
dat<-runif(input$n,-2,2) | ||
} else if (type==3) { | ||
dat<-rlogis(input$n) | ||
} | ||
} | ||
dat <- data.frame(dat) | ||
names(dat) <- c("x") | ||
dat %>% ggplot(aes(x=x))+geom_density(fill="grey")+geom_point(y=0,size=4) | ||
}) | ||
|
||
output$msg <- renderText({ | ||
return(values$status) | ||
}) | ||
|
||
} | ||
|
||
# Run the application | ||
shinyApp(ui = ui, server = 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