我有一个包含3个动作的应用,
通过单击按钮go(左上角)加载数据-图形应立即输出
通过在删除Bod中插入一个单词并单击“ do”来删除单词-图形应该更新
替换一个单词,购买后将要替换的单词放入“查找”,然后将替换的单词放入“替换”并单击“操作”
我面临的问题是,仅当我单击“执行”然后单击“动作”时才显示图形,只有当我单击“动作”时才显示图形
library(shiny)
library(plyr)
library(sp)
library(stringr)
library(tidyr)
library(tidyverse)
library(tm)
library(ggplot2)
library("stringi")
library(plyr)
library(dplyr) #Data manipulation (also included in the tidyverse package)
ui <- fluidPage(
fluidRow(
column( 4, titlePanel("Twitter Analytics")),
column( 3),
column( 4,
textInput("searchstring",
label = "",
value = "")),
column(1,
br(),
actionButton("action", "go"))
),
fluidRow(
column( 12, tabsetPanel(
tabPanel("one",
fluidRow(
column(3, textInput("removeString", label = "remove", value = ""), actionButton("remove", "do"),
textInput("find", label = "find", value = ""),textInput("rep", label = "replace", value = ""),actionButton("replace", "act"),
checkboxGroupInput("checkGroup", "select plots",
choices <- c("Histogram", "Wordcloud", "network")),
sliderInput("topTerms",
label = "top (n) terms",
min = 0, max = 25, value = 0) ),
column(9,fluidRow(column(12,plotOutput("ttext") )),
fluidRow(column(12,wordcloud2Output("wc2"))))
)
),
tabPanel("two"),
tabPanel("three")
)
)
)
)
server <- function(input, output) {
values <- reactiveValues(go = 0, do = 0, act = 0 )
observeEvent(input$action, {
values$go <- 1
values$do <- 0
values$act <- 0
})
observeEvent(input$remove, {
values$go <- 0
values$do <- 1
values$act <- 0
})
observeEvent(input$replace, {
values$go <- 0
values$do <- 0
values$act <- 1
})
#tweet <- eventReactive(input$action,{
cs<- reactiveVal(0)
tweet <-reactive({
if(values$go){
num <- c(1,2,3,4,50)
text <- c("this is love love something", "this is not hate hate hate something", "@something islove rethched this not", " Shiny is love confusing me", "this is hate also somthing difficult")
letter<- c("a", "b", "c", "D", "e")
tweetdf <- data.frame(num, text, letter)
tweetdf$text <- tolower(tweetdf$text)
# tweetdf @UserName
tweetdf$text <- gsub("@\\w+", "", tweetdf$text)
#remove punctuation
tweetdf$text <- gsub("[[:punct:]]", "", tweetdf$text)
#remove links
tweetdf$text <- gsub("http\\w+", "", tweetdf$text)
# Remove tabs
tweetdf$text <- gsub("[ |\t]{2,}", "", tweetdf$text)
# Remove blank spaces at the beginning
tweetdf$text <- gsub("^ ", "", tweetdf$text)
# Remove blank spaces at the end
corpus <- iconv(tweetdf$text, to = "ASCII")
corpus <- Corpus(VectorSource(corpus))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
cleanset <- tm_map(corpus, removeWords, stopwords('english'))
cs(cleanset)}
if(values$do){
cleanset <- cs()
cleanset <- tm_map(cleanset, removeWords, input$removeString)
cs(cleanset)
}
if(values$act){
cleanset <- cs()
cleanset <- tm_map(cleanset, gsub,
pattern = input$find,
replacement = input$rep)
cs(cleanset)
}
else
{return()}
})
output$ttext <- renderPlot({
if(is.null(tweet())){return()}
else{
cleanset <-cs()
tdm <- TermDocumentMatrix(cleanset)
tdm <- as.matrix(tdm)
w <- rowSums(tdm)
library(RColorBrewer)
barplot(w)}
})
output$wc2 <- renderWordcloud2({
if(is.null(tweet())){return()}
else{
library(wordcloud2)
cleanset <-cs()
tdm <- TermDocumentMatrix(cleanset)
tdm <- as.matrix(tdm)
w <- rowSums(tdm)
w <- data.frame(names(w), w)
colnames(w) <- c('word', 'freq')
wordcloud2(w,
color = 'random-dark',
size = 0.7,
shape = 'circle',
rotateRatio = 0.5,
minSize = 1)}
})
}
shinyApp(ui, server)
有人可以告诉我我几天前才开始使用闪亮的产品吗?
答案 0 :(得分:1)
问题出在您使用多个if的事实。 R不知道要返回什么东西。因此,您可以使用此服务器,而无需用Fades w/ UIExtendedSRGBColorSpace 1 0 0 1 done
Fades w/ UIExtendedSRGBColorSpace 1 1 0 1 done
Fades w/ UIExtendedSRGBColorSpace 0 1 0 1 done
animation finshed UIViewAnimatingPosition
animation finished UIViewAnimatingPosition
animation finshed UIViewAnimatingPosition
animation finished UIViewAnimatingPosition
animation finshed UIViewAnimatingPosition
替换0。
FALSE