问题描述
我正在开发一个Shiny应用程序,它具有两个组件Sankey Diagram和一个操作按钮,单击按钮时会弹出"SaveMsg"对话框.
I am developing a Shiny application which has two components Sankey Diagram and one action button which pop up "SaveMsg" dialog box on click of button .
我看到了意外的行为,如果我在一个仪表板上使用了actionbutton和Sankeyvisualization,则在单击action按钮时,仪表板屏幕变灰了.
I am seeing unexpected behavior where, If I user actionbutton and Sankeyvisualization in one dashboard, on click of action button, dashboard screen greyed out.
但是,如果我注释Sankey代码并在UI上仅保留操作"按钮,则操作"按钮将通过显示成功保存"的弹出消息而按预期工作.如果我注释操作按钮代码并仅在用户界面中保留Sankey代码,则可以在仪表板上看到sankey输出.
however If I comment Sankey code and keep only Action button on UI, Action button works as expected by showing pop up message of "save successfull".If I comment action button code and keep only Sankey code in UI, I am able to see sankey output on dashboard.
Sankey代码和操作按钮都可以按预期工作,但是,如果我将它们都放置在一个仪表板中,则操作按钮为灰色的屏幕仪表板屏幕.
Sankey code and action button both are working as expected separately, however if I place both in one dashboard action button greyed outscreen dashboard screen.
我还附上了示例代码-
library(shiny)
library(networkD3)
library(shinydashboard)
value <- c(12,21,41,12,81)
source <- c(4,1,5,2,1)
target <- c(0,0,1,3,3)
edges2 <- data.frame(cbind(value,source,target))
names(edges2) <- c("value","source","target")
indx <- c(0,1,2,3,4,5)
ID <- c('CITY_1','CITY_2','CITY_3','CITY_4','CITY_5','CITY_6')
nodes <-data.frame(cbind(ID,indx))
ui <- dashboardPage(
dashboardHeader(
),
dashboardSidebar(disable = TRUE),
dashboardBody(
fluidPage(
actionLink("savebtn", "Save button")
,sankeyNetworkOutput("simple")
)
)
)
server <- function(input, output,session) {
# Show modal when button is clicked.
observeEvent(input$savebtn, {
showModal(modalDialog(
title = "Save successful"))
})
output$simple <- renderSankeyNetwork({
sankeyNetwork(Links = edges2, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "ID"
,units = "SSN" )
})
}
shinyApp(ui = ui, server = server)
推荐答案
我没有研究这个问题,所以我不确定为什么会这样.但是,如果要显示的模式只是一些文本(不包含闪亮的元素),则可以使用 shinyalert
也可以做模态(尚未在CRAN上发布,尚未发布).这是使用shinyalert的代码.希望有帮助
I haven't dug into the problem so I'm not sure why that's happening. But in case the modal you want to show is just some text (doesn't contain shiny elements), you can use shinyalert
which also does modals (not on CRAN yet, haven't published it yet). Here's your code using shinyalert. Hope that helps
library(shiny)
library(networkD3)
library(shinyalert)
value <- c(12,21,41,12,81)
source <- c(4,1,5,2,1)
target <- c(0,0,1,3,3)
edges2 <- data.frame(cbind(value,source,target))
names(edges2) <- c("value","source","target")
indx <- c(0,1,2,3,4,5)
ID <- c('CITY_1','CITY_2','CITY_3','CITY_4','CITY_5','CITY_6')
nodes <-data.frame(cbind(ID,indx))
ui <- dashboardPage(
dashboardHeader(
),
dashboardSidebar(disable = TRUE),
dashboardBody(
fluidPage(
useShinyalert()
,actionLink("savebtn", "Save button")
,sankeyNetworkOutput("simple")
)
)
)
server <- function(input, output,session) {
# Show modal when button is clicked.
observeEvent(input$savebtn, {
shinyalert("Save successful")
})
output$simple <- renderSankeyNetwork({
sankeyNetwork(Links = edges2, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "ID"
,units = "SSN" )
})
}
shinyApp(ui = ui, server = server)
这篇关于闪亮的App-showModal不会与renderSankeyNetwork一起弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!