Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(rhandsontable)
- library(shinydashboard)
- library(ggplot2)
- library(dplyr)
- setwd("C:/Users/Marc/Dropbox/PROJECTEN/Lopend/shiny_interactive_graph")
- tweets <- data.frame(
- city = c("new york", "texas", "texas"),
- tweet = c("Test1", "Test", "tst")
- )
- shinyApp(
- ui = dashboardPage(
- dashboardHeader(
- title = "Tweetminer",
- titleWidth = 350
- ),
- dashboardSidebar(
- width = 350,
- sidebarMenu(
- menuItem("Menu Item")
- )
- ),
- dashboardBody(
- fluidRow(
- tabBox(
- tabPanel("Set tweets2",
- plotOutput('plot',
- brush = brushOpts(
- id = "plot1_brush"
- )),
- h4("Selected States"),
- verbatimTextOutput("select_states"),
- h4("Selected States' Tweets"),
- verbatimTextOutput("tweets")
- )
- )
- )
- )
- ),
- server = function(input, output) {
- output$plot <- renderPlot({
- all_states <- map_data("state")
- # Add more states to the lists if you want
- states_positive <-c("new york")
- states_negative <- c("texas")
- # Plot results
- ggplot(all_states, aes(x=long, y=lat, group = group)) +
- geom_polygon(fill="grey", colour = "white") +
- geom_polygon(fill="green", data = filter(all_states, region %in% states_positive)) +
- geom_polygon(fill="red", data = filter(all_states, region %in% states_negative))
- })
- selected_points <- reactiveVal()
- observeEvent(input$plot1_brush,{
- all_states <- map_data("state")
- selected_points( brushedPoints(all_states, input$plot1_brush))
- })
- observeEvent(selected_points(), {
- showModal(modalDialog(
- title = "Important message",
- tweets[(tweets$city %in% brushed_states()),],
- easyClose = TRUE
- ))
- })
- output$brush_info <- renderPrint({
- all_states <- map_data("state")
- brushedPoints(all_states, input$plot1_brush)
- })
- #get states from brushed coordinates
- brushed_states <- reactive({
- all_states <- map_data("state")
- brushed <- brushedPoints(all_states, input$plot1_brush)
- unique(brushed$region)
- })
- #this is to show the selected states
- output$select_states <- renderText({
- brushed_states()
- })
- output$tweets <- renderPrint({
- tweets[(tweets$city %in% brushed_states()),]
- })
- })
- tweets[(tweets$city %in% brushed_states()),]
- texas Test
- texas Test
- texas tst
- Warning in charToRaw(enc2utf8(text)) :
- argument should be a character vector of length 1
- all but the first element will be ignored
Add Comment
Please, Sign In to add comment