在闪亮中制作一个反应性全局变量
Making a reactive global variable in shiny
我想在用户单击(工具提示)对象时将一些文本附加到 ggvis 图下方的面板。这是来自单独工具提示的悬停消息的补充。就目前而言:
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')
)
据我所知,这应该通过 runApp()
调用工作,但我发现面板中的文本不可靠(至少当服务器首先 运行 出现时)在图下方,如果在后续页面调用中确实出现,则不会在新点击时刷新。 This shinyapps.io app demonstrates.
代码 确实 然而,当 运行 在 RStudio 中使用 shinyApp(ui, server)
方法在单个脚本中以交互方式工作时。但是我无法获得在 shinyapps.io 上托管所需的 runApp()
执行方法。非常感谢您的帮助。
我不是你想要的 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)
好的,下面的内容确实适用于 shinyapps.io
(即 app.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)
我想在用户单击(工具提示)对象时将一些文本附加到 ggvis 图下方的面板。这是来自单独工具提示的悬停消息的补充。就目前而言:
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')
)
据我所知,这应该通过 runApp()
调用工作,但我发现面板中的文本不可靠(至少当服务器首先 运行 出现时)在图下方,如果在后续页面调用中确实出现,则不会在新点击时刷新。 This shinyapps.io app demonstrates.
代码 确实 然而,当 运行 在 RStudio 中使用 shinyApp(ui, server)
方法在单个脚本中以交互方式工作时。但是我无法获得在 shinyapps.io 上托管所需的 runApp()
执行方法。非常感谢您的帮助。
我不是你想要的 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)
好的,下面的内容确实适用于 shinyapps.io
(即 app.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)