2017-06-08 7 views
2

私は最初の光沢のあるアプリを構築しようとしており、解決できないエラーが出てきました。私は検索して検索しましたが、この質問を解決する答えが見つからないようです。R shiny app with ggplot2 error

私のコードは、mtcarsデータセットを使用して以下のとおりです。目標は、調査データセット用のビジュアルおよびテキスト分析ツールを開発することです。私は現在、アンケートの質問を含む2つのドロップダウンメニュー、グループ化変数メニューを持つドロップダウンメニュー、およびプロットタイプのいくつかのラジオボタンを持っています。私は最初のプロット - ヒストグラムを作成しようとしています。私は私が正しくレンダリングされたデータテーブルを取得するコード、ないヒストグラムプロットを実行した後 - とエラー:

オブジェクトを私がして(プリントで自分のggplotコードをラップすることなくこれを試してみました

を見つけていない「S1」 )。

ご協力いただければ幸いです。

ありがとうございます!


library(shiny) 
install.packages("shinythemes") 
library(shinythemes) 
library(ggplot2) 
library(dplyr) 

mt <- mtcars 
ui <- fluidPage(theme=shinytheme("readable"), 

       titlePanel("Test"), 

       sidebarLayout(

        sidebarPanel(
        # use mpg and cyl as survey option groups 
        selectizeInput(inputId = 's1', 
            label = 'Survey Question 1 (X-Axis)', 
            choices = c("mpg", "cyl")), 

        selectizeInput(inputId = 's2', 
            label ='Survey Question 2 (Y-Axis)', 
            choices = c("mpg", "cyl")), 

        # use gear and vs as grouping variables 
        selectizeInput(inputId = 'g', 
            label = 'Group By', 
            choices = c("Gear"="gear", "VS" = "vs")), 

        # use radio buttons for pot type options 
        radioButtons(inputId = 'plottype', 
           label = 'Plot Type', 
           choices = c("Histogram" = "geom_histogram", "Box Plot" = "geom_boxplot", "Scatterplot" = "geom_point") 
        ) 
       ), 
         mainPanel(
         plotOutput("plot1"), # ui for plot 
         verbatimTextOutput("table1") # ui for table 
        ) 
       ) 
) 

server <- function(input, output, session) { 

## subset dataset to include only two options for now - include grouping after 
    plotData <- reactive({ 
    ((mt[,c(input$s1,input$s2)])) ## data for plot 
    }) 

## render hist plot in ggplot 
output$plot1 <- renderPlot({ 
    d1<-(plotData()) 
print(ggplot(d1, aes(x=s1)) + geom_histogram(fill = "dark green", alpha = 0.6, binwidth = 1)) 
    print(str(d1)) 
    }) 

## render summary table for survey questions 
output$table1 <- renderPrint({ 
    summary(plotData()) 
    }) 
} 
shinyApp(ui = ui, server = server) 

## but this works 
ggplot(mt, aes(x=mpg)) + geom_histogram(fill = "dark green", alpha = 0.6, binwidth = 1) 

答えて

1

データでs1d1を設定する一切の列はありません。 ggplot(d1, aes_string(x=input$s1))を使用してください。

+0

Augh - お返事ありがとうございます!今それは動作します! – JC31