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

Can Shiny use inputs that are blocked by quotes?

我正在开发一个相对简单的 shiny 应用程序,我希望用户在其中键入几个自由文本关键字,让 Shiny 服务器代码查询 table 和 create/refresh "trend" new/existing 列,然后在分面网格上绘制该系列。

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

我的 运行 理论(可能不是真正的错误)是在 stringr 函数中找不到无功输入。由于未找到它们,因此 "trend" 频率为 0,因为任何内容/字数都将为 0。关于如何逃避的任何想法?

闪亮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")))))

闪亮服务器

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))
})

我不知道这是否是问题所在,但您不应该在 output$enrongraph <- renderPlot({...}) 中调用 renderPlot。只需让 ggplot(...) 调用外部 renderPlot 中的最后一个值并删除第二个 renderPlot.

像这样:

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