Shiny :: nonstandard evaluation
Ex1 >
> library(ISLR)
> library("ISLR")
> aaa <- "ISLR"
> library(aaa)
Error in library(aaa) : there is no package called ‘aaa’
Ex2> ggplot
p <- ggplot(mtcars, aes(c(input$sel, mpg, colors=as.factor(cyl))) +
geom_point()
print(p)
이유는 그냥 ggplot 을 사용했기 때문
Warning: Error in renderPlot: object 'cyl' not found ERROR: Unknown input:tbl_df Don't know how to automatically pick scale for object of type ... Warning: Error in : Aesthetics must be either length 1 or the same as the data (11): x, y
Shiny내에서 ggplot 사용방법

library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("simple"),
selectInput("sel", "select:", choices = c("wt","hp", "disp")),
plotOutput("simpleplot"))
server <- function(input, output, session){
output$simpleplot<- renderPlot({
mtcars$cyl <- as.factor(mtcars$cyl)
p <- ggplot(mtcars) + aes_string(input$sel, "mpg", colors="cyl") +
geom_point()
print(p)
})
}
shinyApp(ui,server)
Shiny에서 쓰이는 함수
- switch()
- get() : Object 찾기
- assign() : object를 다른 이름으로 저장