Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Created July 11, 2013 06:17
Show Gist options
  • Save benmarwick/5972950 to your computer and use it in GitHub Desktop.
Save benmarwick/5972950 to your computer and use it in GitHub Desktop.
basic sketch of a locally-hosted web app using shiney and JSTORr. Depends on having run a few functions to prepare the data in advance...
# to make it work...
setwd("C:\\Users\\marwick\\Downloads\\shiny")
# make sure the 'shiny_data.RData' object is in there
# this is the just the result of unpack1grams() for the
# three journals
# then load the package
library(shiny)
# this line fires it up in a browser
runApp()
# here are the bits that make it work:
# save this part in a file called ui.R
################################
library(shiny)
# Define UI for dataset viewer application
shinyUI(pageWithSidebar(
# Application title
headerPanel("JSTOR text analyser"),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("American Antiquity",
"Biostatistika",
"On Our Backs")),
textInput("onegram", "onegram:", "diamond"),
textInput("cor1", "correlate word one:", "United"),
textInput("cor2", "correlate word two:", "States")
),
mainPanel(
h3(textOutput("onegram")),
plotOutput("plot" , height="400px"),
plotOutput("plot2", height="400px")
)
))
################################
# save this part in a file called server.R
################################
library(shiny)
library(JSTORr)
options(shiny.trace=TRUE)
load("shiny_data.RData")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"American Antiquity" = unpack1gramsAA,
"Biostatistika" = unpack1gramsBS,
"On Our Backs" = unpack1gramsOB)
})
output$plot <- renderPlot({
p <- JSTOR_1word(datasetInput(), oneword = input$onegram)
print(p)
})
output$plot2 <- renderPlot({
p <- JSTOR_2wordcor(datasetInput(), word1 = input$cor1, word2 = input$cor2)
print(p)
})
})
################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment