Scala REPL:如何加载特定的包/类/对象?

时间:2016-08-17 08:51:16

标签: scala package read-eval-print-loop

我们说我有以下文件:

package PackName

class Class1 { 
   def func11():
   ....
   def func12():
   ...
}

class Class2 { 
  def func21():
  ...
  def func22():
  ...
}

如果我想从REPL中调用类1中的func11,我必须运行REPL并调用:

  

PackName.Class1.func11()。

我是否可以选择加载REPL类PackName.Class1,因此我不必输入" PackName.Class1"每当我调用这个类的函数时?

1 个答案:

答案 0 :(得分:1)

library("shiny")
library("ggplot2")
library('readxl')
library('gridExtra')

ui<- fluidPage(
   titlePanel("Animals"),
   sidebarLayout(
     sidebarPanel(
  helpText("Create graph of height and/or weight animals"),
  selectInput("location", 
              label = "Choose a location",
              choices = list("New York"="New York", "Philadelphia" = "Philadelphia"),
              selected = "New York"),
  uiOutput("animal"),
  checkboxGroupInput("opti", 
              label = "Option",
              choices = c("weight", "height"),
              selected = "weight")
  ),
mainPanel(plotOutput("graph"))
))

server <- function(input, output){
  animal <- read_excel('data/animals.xlsx', sheet =1)
  var <- reactive({
    switch(input$location,
       "New York" = list("Cat1", "Dog2"),
       "Philadelphia"= list("Cat4","Dog3"))
     })

  output$animal <- renderUI({
  checkboxGroupInput("anim", "Choose an animal",
                   var())
  })

output$graph <- renderPlot({
  if (length(input$anim)==1){
    p <- ggplot(subset(animal, Name %in% input$anim & Location %in% input$location), aes(x=date))
    if ("weight" %in% input$opti){
      p <- p + geom_line(aes(y=weight)) + geom_point(aes(y=weight))
    }
    if ("height" %in% input$opti){
      p <- p + geom_line(aes(y=height)) + geom_point(aes(y=height))
    }
    print(p)
  }

  if (length(input$anim)==2){
    p1 <- ggplot(subset(animal, Name %in% input$anim[1] & Location %in% input$location), aes(x=date))
    p2 <- ggplot(subset(animal, Name %in% input$anim[2] & Location %in% input$location), aes(x=date))
    if ("weight" %in% input$opti){
      p1 <- p1 + geom_line(aes(y=weight)) + geom_point(aes(y=weight))
      p2 <- p2 + geom_line(aes(y=weight)) + geom_point(aes(y=weight))
    }
    if ("height" %in% input$opti){
      p1 <- p1 + geom_line(aes(y=height)) + geom_point(aes(y=height))
      p2 <- p2 + geom_line(aes(y=height)) + geom_point(aes(y=height))
    }
    grid.arrange(p1,p2, ncol = 2)
  }
})
}
shinyApp(ui=ui, server= server)