2017-05-18 8 views
0

オブジェクト上でユーザーが(ツールチップ)をクリックすると、ggvisプロットの下のパネルにテキストを追加したいと考えています。これは、別のツールチップからのホバーメッセージに加えてあります。私の知る限りrunApp()呼び出しを介して動作するはずです、これを言うことができるように光沢のある反応性のあるグローバル変数を作成

server.R

require(ggvis); require(shiny) 

pet_rep <<- '' 

tooltip_headline = function(x) "Headline detail. Click to open full detail below" 

tooltip_values = function(x){ 
    pet_rep <<- sample(LETTERS, 26) %>% paste(collapse=' ') 
    return(pet_rep) 
} 

function(input, output, session) { 
    output$petreport = renderUI({HTML(paste0('<h1>', pet_rep, '</h1>'))}) 
    observe({ 
    ggvis(mtcars, ~disp, ~mpg) %>% layer_points() %>% 
     add_tooltip(tooltip_headline, 'hover') %>% 
     add_tooltip(tooltip_values, 'click') %>% 
     bind_shiny('ggvis_plot', 'ggvis_ui') 
    }) 
} 

ui.R

require(ggvis); require(shiny) 

fluidPage(
    makeReactiveBinding("pet_rep"), 
    uiOutput("ggvis_ui"), ggvisOutput("ggvis_plot"), 
    uiOutput('petreport') 
) 

を、私は見つける:それは現状ではテキストは信頼できるように(少なくともサーバが最初にそれを実行したときは)、プロットの下のパネルに表示され、その後のページ呼び出しでは新しいクリックで更新されないように見えます。 shinyApp(ui, server)アプローチを使用して、単一のスクリプトでRStudioで対話的に実行したときにThis shinyapps.io app demonstrates.

コードしかし動作しません。しかし、私はrunApp()の実行アプローチをshinyapps.ioのホスティングに必要なものにすることはできません。援助に感謝します。

答えて

0

OK次はshinyapps.ioapp.Rとすなわち、単一のファイル・アプローチ)の作業を行いますので:

app.R

require(ggvis); require(shiny) 

pet_rep <<- '' 

tooltip_headline = function(x) "Headline detail. Click to open full detail below" 

tooltip_values = function(x){ 
    pet_rep <<- sample(LETTERS, 26) %>% paste(collapse=' ') 
    return(pet_rep) 
} 

server = function(input, output, session) { 
    output$petreport = renderUI({HTML(paste0('<h1>', pet_rep, '</h1>'))}) 
    observe({ 
    ggvis(mtcars, ~disp, ~mpg) %>% layer_points() %>% 
     add_tooltip(tooltip_headline, 'hover') %>% 
     add_tooltip(tooltip_values, 'click') %>% 
     bind_shiny('ggvis_plot', 'ggvis_ui') 
    }) 
} 

ui = fluidPage(
    makeReactiveBinding("pet_rep"), 
    uiOutput("ggvis_ui"), ggvisOutput("ggvis_plot"), 
    uiOutput('petreport') 
) 

shinyApp(ui, server) 
0

あなたが望むものは100%ではありませんが、これはそれですか?

require(ggvis); require(shiny) 
pet_rep <<- '' 
tooltip_headline = function(x) "Headline detail. Click to open full detail below" 
tooltip_values = function(x){ 
    pet_rep <<- sample(LETTERS, 26) %>% paste(collapse=' ') 
    return(pet_rep) 
} 

ui <- fluidPage(
    uiOutput("ggvis_ui"), 
    ggvisOutput("ggvis_plot"), 
    uiOutput('petreport') 
) 

server <- function(input, output, session) { 

    observe({ 
    makeReactiveBinding("pet_rep") 
    }) 

    output$petreport = renderUI({ 
    HTML(paste0('<h1>', pet_rep, '</h1>'))}) 

    ggvis(mtcars, ~disp, ~mpg) %>% layer_points() %>% 
    add_tooltip(tooltip_headline, 'hover') %>% 
    add_tooltip(tooltip_values, 'click') %>% 
    bind_shiny('ggvis_plot', 'ggvis_ui') 

} 

runApp(shinyApp(ui, server), launch.browser = TRUE) 

enter image description here

+0

ミスター/ミセスチョップ、することができますあなたはこれがあなたのために適切に動作するかどうかを確認することがありますすなわち、パネルは適切に反応するか?私にとっては、これは、ブラウザを2回目のインスタンスにリダイレクトしてから反応しない場合にのみ機能します。 – geotheory

関連する問題