可以使用被引号阻止的输入吗?

时间:2015-07-11 21:08:11

标签: r ggplot2 shiny stringr

我正在开发一个相对简单的闪亮应用,我希望用户输入几个自由文本关键字,让Shiny服务器代码查询表并创建/刷新"趋势"新建/现有列,然后在构面网格上绘制该系列图。

应用程序本身会运行并显示图表,但它似乎并没有获取任何数据。图表目前显示所有观察结果为零。

我的运行理论(可能不是真正的错误)是在stringr函数中找不到被动输入。因为他们没有找到"趋势"频率为0,因为一切都没有/字数为0。关于如何逃避的任何想法?

Shiny UI

shinyUI(fluidPage(titlePanel("Enron Email Analysis"),
     sidebarLayout(position = "lef",
            sidebarPanel( h4("What was Enron saying as the ship started sinking?"), 
                          p("Find out now - search for the relative frequency of keywords over three years of enron emails."),
                          p("To view where Enron employees were communicating uncertainty over time use the recommended keywords."),
                          br(),
                          textInput("key1","Keywords","?"),
                          textInput("key2","","maybe"),
                          textInput("key3","","think"),
                          textInput("key4","","believe"),
                          textInput("key5","","don't know"),
                          textInput("key6","","could"),
                          textInput("key7","","might"),
                          textInput("key7","","uncertain")
                         ),
            mainPanel("", plotOutput("enrongraph")))))

Shiny Server

shinyServer(function(input, output) { 
    output$enrongraph <- renderPlot({

    ## loading data ##
       enronpool <-read.csv("/Users/michaelcata/Documents/Enron/Enronapp/EnronBagofWordsInternal.csv",check.names=FALSE)

    ## changing the column names ##
       setnames(enronpool,"concat(subject,\" \",body)","text")

    ## changing format ##
       enronpool$text <- as.character(enronpool$text)

    ## creating rank for hierarchy ##
       enronpool$hier <- factor(enronpool$hier, levels = c("CEO", "President", "Vice President", "In-House Lawyer", "Managing Director", "Director", "Manager", "Trader", "Employee", "N/A"))

    ## creating rank for message direction ##
       enronpool$direct <- factor(enronpool$direct, levels = c("Above","Peer","Below"))

   ## creating word frequency trend -- here's where the issue may be ##
       enronpool$trend <- (str_count(enronpool$text, " input$key1 | input$key2 | input$key3 | input$key4 | input$key5 | input$key6 | input$key7"))/str_count(enronpool$text,"\\S+")

   ## plot ##

       ggplot(enronpool, aes(newdate,trend))+facet_grid(direct~hier, scales="fixed")+geom_smooth(aes(group=hier, color=hier),breaks=FALSE)+theme(legend.position="none")+labs(x='Mid 1998 - Late 2002',y="Uncertainty in Tone")+geom_rect(aes(xmin='2001-08-22', xmax='2001-09-02', ymin=0,ymax=+Inf), alpha=0.2, fill="grey")+ylim(-.01,.05))
})

1 个答案:

答案 0 :(得分:0)

我不知道这是不是问题,但你不应该在renderPlot内打电话给output$enrongraph <- renderPlot({...})。只需将ggplot(...)调用外部renderPlot中的最后一个值,然后删除第二个renderPlot

像这样:

output$enrongraph <- renderPlot({
  ...
  ...
  ...
  ggplot(enronpool, ...)
})