问题描述
我是 R-shiny 的新手。我想要做的是一个与这里给出的主题比例随时间变化的图相似的图https://tm4ss.github.io/docs/Tutorial_6_Topic_Models.html#6_Topic_proportions_over_time 我可以在 r-studio 中完成,但不了解如何在 r-shiny(dashboard) 中执行此操作,我想要做的是首先在 rshiny 中上传文件并使用该文件作为主题模型的 ggplot 选项卡(因为我们有三个不同的标签)。在仪表板中,其他选项卡,如主题模型可视化 (LDA) 和关于我没有问题,但唯一的问题是我在一段时间内遇到了关于主题模型面板选项卡 的问题。在这个面板中,我想上传 vis 文件并根据 vis.csv 文件制作一个 ggplot。我附上了代码。
library(shiny)
library(shinydashboard)
library(shinyjs)
library(corporaexplorer)
library(LDAvis)
library(TramineR)
ui<-fluidPage(
useShinyjs(),# Application title
titlePanel("LGBTQ+ AV Mining"),# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
actionButton("show","Content Warning"),div(id="contentwarningBox",checkBoxInput(inputId="contentwarning","AckNowledge Content Warning",value = FALSE,width = NULL)),div(id="topicselector",sliderInput("nTerms","Number of terms to display",min = 4,max = 12,value = 5)),),# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Topic modeling visualization",{
div(id="chart",visOutput('myChart')
)
}),tabPanel("Topic Modeling over time",{
div(id = "advanced",plotOutput('ggplot'),)
}),tabPanel("About",p('
Thohathe
'))
),shinyjs::hidden(
div(id = "advanced2",print("TEST")
)
)
)))
library(shiny)
library(LDAvis)
library(ggplot2)
json <- readRDS("lda_topics/lda_5_terms.RDS")
#write.csv(vizDataFrame,'vis.csv')
#viss<-read.csv("C:\\Users\\syeda\\Documents\\syeda_demo\\transcripts\\vis.csv")
server<-function(input,output) {
topicValues <- reactive({
Value = readRDS(paste("lda_topics/lda_",input$nTerms,"_terms.RDS",sep=""))
# output$myChart <- renderVis(json)
})
output$myChart <- renderVis({topicValues()})
show(id="chart")
####
#topicvalues2 = read.csv("C:\\Users\\syeda\\Documents\\syeda_demo\\7.2.21_demo\\vis.csv")
output$ggplot<-renderPlot(function(){
topicValues2 <- fread(input$vis.csv)
#header = input$header,#sep = input$sep,#quote = input$quote)
#if(is.null(data)) return(NULL)
#topicValues2<-input$topicvalues2
ggplot(topicValues2,aes(x=year,y=value,fill=variable)) +
geom_bar(stat = "identity") + ylab("proportion") +
scale_fill_manual(values = paste0(alphabet(20),"FF"),name = "year") +
theme(axis.text.x = element_text(angle = 90,hjust = 1))})
##########
#Value2<-data.frame(value2)
#topicValues2<-reactive({
# Value2=readRDS(paste("my",input$values,"_data.RDS",sep=""))
#})
#output$output.show2 <- renderPlot({
# ggplot(Value2,fill=variable)) +
# geom_bar(stat = "identity") + ylab("proportion") +
# scale_fill_manual(values = paste0(alphabet(20),name = "year") +
# theme(axis.text.x = element_text(angle = 90,hjust = 1))})
show(id="advanced")
####
show(id="topicselector")
# output$myChart <- renderVis(json)
shinyjs::onclick("contentwarning",{values$show2 <- TRUE
return(values$show2)} )
# shinyjs::onclick("contentwarning",shinyjs::toggle(id = "advanced2",anim = TRUE))
shinyjs::onclick("contentwarning",{
show(id="contentwarningBox",anim=TRUE)
show(id = "chart",anim = TRUE)
show(id="topicselector",anim=TRUE)
shinyjs::toggle(id = "advanced",anim = TRUE)
})
### Testing
values <- reactiveValues()
values$show <- FALSE
output$show <- reactive({
return(values$show2)
})
###
observeEvent(input$show,{
showModal(modalDialog(
title = "Language and Subject Matter","
It is always important for people
",easyClose = TRUE
))
})
}
shinyApp(ui,server)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)