R 闪亮的htmlOutput不';不要对第二次输入变化做出反应

R 闪亮的htmlOutput不';不要对第二次输入变化做出反应,r,shiny,R,Shiny,我有shinyapp来生成谷歌单词树可视化。 shinyapp接口有两个输入。文本和术语。 我为所选文本子集data.frame并替换html模板中所需的内容 模板在这里 问题是,shinyapp只改变了一次。当我第二次更改文本或术语时,html页面变为白色。当我检查文件夹中的文件时,我看到html文件内容发生了变化,但它并没有显示在闪亮的页面上 app.R shinyApp( ui = fluidPage( fluidRow( column(width = 6, se

我有shinyapp来生成谷歌单词树可视化。 shinyapp接口有两个输入。文本和术语。 我为所选文本子集data.frame并替换html模板中所需的内容

模板在这里

问题是,shinyapp只改变了一次。当我第二次更改文本或术语时,html页面变为白色。当我检查文件夹中的文件时,我看到html文件内容发生了变化,但它并没有显示在闪亮的页面上

app.R

shinyApp(
  ui = fluidPage(
    fluidRow(
      column(width = 6,  selectInput("input.filter", label = "selec text", choices = mytexts$yazi.header, selected = "text 1")) ,
      column(width = 6,textInput("input.term", "type term", "today"))
      ),
    fluidRow(tags$head(titlePanel("title panel"))),
    fluidRow(htmlOutput("treehtml")) 
  ) ,
server = function(input, output, session) { 
  output$treehtml <- reactive({
    print(input$input.filter)
    print(input$input.term)
    xid <- subset(mytexts, yazi.header == if(is.null(input$input.filter)) {"text 1"} 
                  else {input$input.filter} ) 
    print(xid$L1)
    xxwt <- mytexts.cumle[mytexts.cumle$cumleid == xid$L1, ]
    xxwt <- paste("['", paste(xxwt$clean, collapse = "'], ['"), "'],", sep = "")
    wttemp <- paste(readLines("wordtree/_wordtree_tmp.html"), collapse="\n")
    wttemp <- gsub("today",input$input.term, wttemp, fixed = TRUE)
    wttemp <- gsub("['DEMO1 DEMO2 DEMO3'],",xxwt, wttemp, fixed = TRUE)
    write(wttemp, "wordtree/wttemp.html")
    wttemp
    })
})
shinyApp(
ui=fluidPage(
fluidRow(
列(宽度=6,选择输入(“input.filter”,label=“selec text”,choices=mytext$yazi.header,selected=“text 1”),
列(宽度=6,textInput(“input.term”,“type term”,“today”))
),
fluidRow(标签$head(标题面板(“标题面板”)),
fluidRow(htmlOutput(“treehtml”))
) ,
服务器=函数(输入、输出、会话){

输出$treehtml例如,您可以使用
shinyjs
的函数
runjs
执行以下操作

library(shiny)
library(shinyjs)
library(jsonlite)

sentences <- data.frame(
  group = c("A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B"),
  sentence = c("Phrases", "cats are better than dogs", "cats eat kibble", 
               "cats are better than hamsters", "cats are awesome", "cats are people too", 
               "cats eat mice", "cats meowing", "cats in the cradle", "cats eat mice", 
               "cats in the cradle lyrics", "cats eat kibble", "cats for adoption", 
               "cats are family", "cats eat mice", "cats are better than kittens", 
               "cats are evil", "cats are weird", "cats eat mice"),
  stringsAsFactors = FALSE
)    

drawChart <- function(sentences, word){
  sprintf("google.charts.load('current', {packages:['wordtree']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable(
          %s
  );

  var options = {
    wordtree: {
      format: 'implicit',
      word: '%s'
    }
  };

  var chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
  chart.draw(data, options);
}
", toJSON(sentences), word)
}

shinyApp(
  ui = fluidPage(
    tags$head(
      tags$script(src="https://www.gstatic.com/charts/loader.js")
    ),
    useShinyjs(),
    fluidRow(
      column(width=6, 
        selectInput("filter", label="select group", choices=c("A","B"), selected="A", selectize=FALSE)
      ),
      column(width=6, 
        textInput("word", "type word", "cats")
      )
    ),
    fluidRow(tags$head(titlePanel("title panel"))),
    fluidRow(tags$div(id="wordtree_basic", style="width: 900px; height: 500px;")) 
  ),

  server = function(input, output, session) { 
    observe({
      dat <- subset(sentences, group==input$filter)$sentence
      sentences <- array(dat, dim=c(length(dat),1))
      runjs(drawChart(sentences, input$word))
    })
  }
)
库(闪亮)
图书馆(shinyjs)
图书馆(jsonlite)

我不知道这是否是原因,但你应该避免输入id中的点(比如
input.term
)谢谢,我以前没听说过。我试过了,但没用。你没有在你的帖子中提供数据框
mytext
mytext.cumle
。所以我们无法复制。而且
\u wordtree\u tmp.html
是“完整的”html文件,带有
html
head
body
标记。你的应用程序将此html放在
div
中,并应该呈现此html。我不是html专家,但如果可以做到这一点,我会感到惊讶。无论如何,这并不是一种严肃的呈现此图形的方法……我将向你展示如何清晰地呈现此html,但是t这需要一点时间。此外,您可能对这个R包感兴趣(在页面中搜索“对角网络”)
library(shiny)
library(shinyjs)
library(jsonlite)

sentences <- data.frame(
  group = c("A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B"),
  sentence = c("Phrases", "cats are better than dogs", "cats eat kibble", 
               "cats are better than hamsters", "cats are awesome", "cats are people too", 
               "cats eat mice", "cats meowing", "cats in the cradle", "cats eat mice", 
               "cats in the cradle lyrics", "cats eat kibble", "cats for adoption", 
               "cats are family", "cats eat mice", "cats are better than kittens", 
               "cats are evil", "cats are weird", "cats eat mice"),
  stringsAsFactors = FALSE
)    

drawChart <- function(sentences, word){
  sprintf("google.charts.load('current', {packages:['wordtree']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable(
          %s
  );

  var options = {
    wordtree: {
      format: 'implicit',
      word: '%s'
    }
  };

  var chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
  chart.draw(data, options);
}
", toJSON(sentences), word)
}

shinyApp(
  ui = fluidPage(
    tags$head(
      tags$script(src="https://www.gstatic.com/charts/loader.js")
    ),
    useShinyjs(),
    fluidRow(
      column(width=6, 
        selectInput("filter", label="select group", choices=c("A","B"), selected="A", selectize=FALSE)
      ),
      column(width=6, 
        textInput("word", "type word", "cats")
      )
    ),
    fluidRow(tags$head(titlePanel("title panel"))),
    fluidRow(tags$div(id="wordtree_basic", style="width: 900px; height: 500px;")) 
  ),

  server = function(input, output, session) { 
    observe({
      dat <- subset(sentences, group==input$filter)$sentence
      sentences <- array(dat, dim=c(length(dat),1))
      runjs(drawChart(sentences, input$word))
    })
  }
)