闪亮的htmlOutput对第二次输入变化没有反应

时间:2017-02-19 16:11:53

标签: r shiny

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

模板在这里https://developers.google.com/chart/interactive/docs/gallery/wordtree

问题是,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
    })
})

wordtree / _wordtree_tmp.html

<html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {packages:['wordtree']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {
      var data = google.visualization.arrayToDataTable(
        [ ['DEMO DEMO DEMO'], ]
      );

      var options = {
        wordtree: {
          format: 'implicit',
          type: 'double',
          word: 'today'
        }
      };

      var chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
      chart.draw(data, options);
    }
    </script>
</head>
<body>
      <div id="wordtree_basic" style="width: 900px; height: 500px;"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您可以使用runjs的{​​{1}}函数执行以下操作。

shinyjs

enter image description here

enter image description here