2

I'm trying to understand how ggvis works in the context of shiny and it's been a real headache. At this point I'm just trying to make something, anything interactive. Ideally I would like to be able to filter data points with sliders and be able to click on sectors and links to zoom and highlight respectively.

Ignoring the entire right bar, how would I be able to implement ggvis?

server.r

options(shiny.maxRequestSize=60*1024^2)
# Option to use scientific notation 
options(scipen=999)

library(ggplot2)
library(ggvis)

shinyServer(function(input, output) {

inputData <- try(reactive({  

inFile <- input$file1

if(is.null(inFile$datapath)){
  return(iris)
}

newData <- read.csv(inFile$datapath, fill=TRUE)
newData
}))

output$choose_histVar <- renderUI({

newData <- inputData()   

nameDataNew1<-c("ALL" ,"Earmarks", "Free-Cash")
if(class(nameDataNew1)!="try-error"){
  selectInput("histVar", "1. Select Funding", as.list(nameDataNew1), 
multiple = FALSE)
}
else{
  selectInput("histVar", "1.Select Funding", NULL, multiple = FALSE)
}

})

# Use renderTable() function to render a table 
output$summaryTable <- renderTable({ summary( try(inputData()) ) })

output$plot.hist <- renderPlot({ 
plotHistograms(data=try(inputData()), getCol=input$histVar, 
getBin=input$bins) 
})

output$plot.bar <- renderPlot({ plotcir(data)}) 
})

plotcir <- function(data) {

set.seed(999)
n = 1000
df = data.frame(factors = sample(letters[1:8], n, replace = TRUE),
              x = rnorm(n), y = runif(n))
data.temp <- as.data.frame(df) 

circos.par("track.height" = 0.1)
circos.initialize(factors = df$factors, x = df$x)

circos.track(factors = df$factors, y = df$y,
           panel.fun = function(x, y) {
             circos.text(CELL_META$xcenter, CELL_META$cell.ylim[2] + uy(5, 
                             "mm"), 
                         CELL_META$sector.index)
             circos.axis(labels.cex = 0.6)
           })

col = rep(c("#FF0000", "#00FF00"), 4)

circos.trackPoints(df$factors, df$x, df$y, col = col, pch = 16, cex = 0.5)

circos.text(-1, 0.5, "text", sector.index = "a", track.index = 1)

bgcol = rep(c("#EFEFEF", "#CCCCCC"), 4)
circos.trackHist(df$factors, df$x, bin.size = 0.2, bg.col = bgcol, col = NA)


circos.track(factors = df$factors, x = df$x, y = df$y,
           panel.fun = function(x, y) {
             ind = sample(length(x), 10)
             x2 = x[ind]
             y2 = y[ind]
             od = order(x2)
             circos.lines(x2[od], y2[od])
           })

##vis <- reactive({})

circos.link("a", 0, "b", 0, h = 0.4)
circos.link("c", c(-0.5, 0.5), "d", c(-0.5,0.5), col = "red",
          border = "blue", h = 0.2)
circos.link("e", 0, "g", c(-1,1), col = "green", border = "black", lwd = 2, 
lty = 2)
}

ui.r

# Load libraries used in this Shiny App 
library(shiny)
library(ggplot2)
library(circlize)
library(ggvis)
library(shinythemes)

shinyUI(fluidPage(

titlePanel(title = h2("The Wall", align="center")),
theme = shinytheme("cyborg"),

sidebarPanel(

fileInput('file1', 'The default dataset is df data. You may choose your own 
CSV file'), 
sliderInput('file1', 'Mission 1', value = 10, min = 0, max = 100, step = 1, 
post = "%"),
sliderInput('file1', 'Mission 2', value = 0, min = 0, max = 100, step = 1, 
post = "%"),
sliderInput('file1', 'Mission 3', value = 0, min = 0, max = 100, step = 1, 
post = "%"),
sliderInput('file1', 'Mission 4', value = 0, min = 0, max = 100, step = 1, 
post = "%"),
sliderInput('file1', 'Mission 5', value = 0, min = 0, max = 100, step = 1, 
post = "%"),
uiOutput("choose_histVar"),
uiOutput("choose_xVar"),
uiOutput("choose_yVar"),
uiOutput("choose_cateVar"),
uiOutput("choose_barVar"),
p()   
),   

mainPanel(

h3('DOS - Augmented decisions'),
tabsetPanel(type="tab", 
  tabPanel( "Optimal",
    plotOutput('plot.bar')
  ),

  tabPanel("Histogram",

    h4(checkboxInput("showHideHistograms", "Show/hide histograms", 
    value=FALSE)),

    # Add a conditional panel to plot the histogram only when "Show 
     histogram" is checked 
     conditionalPanel(
       condition = "input.showHideHistograms",
       # Use plotOutput function to plot the output visualization
       plotOutput('plot.hist')    
     )
  )
),

p('')    

)  
))
cramopy
  • 3,459
  • 6
  • 28
  • 42
adarvishian
  • 175
  • 1
  • 3
  • 11

0 Answers0