ShinyAlert 本地图片出错(执行顺序)
ShinyAlert goes wrong with local image (order of execution)
我运行遇到以下问题
使用 ShinyAlert * 如果我在消息中添加一个 imageUrl,如果它是一个互联网 url 地址,没问题,消息出现,图像立即出现,然后其他代码片段 运行 ,
但
如果它是我硬盘上的图像,则会发生这种情况:
没有图像的消息打开
消息 运行s 之后的其他代码
然后图像出现..
我不知道为什么,我现在已经在 3 台不同的计算机上尝试过,并使用 js swal 方法对其进行了测试,同样的问题:
library(shiny)
library(sweetalertR)
library(shinyjs)
library(shinydashboard)
ui <- fluidPage(
shinyjs::useShinyjs(),
useShinyalert(),
textInput("expr", label = "Enter an R expression",
value = "bio",width="600px"),
actionButton(inputId ="mybutton", "Run")
)
server <- function(input, output, session) {
shinyEnv <- environment()
observeEvent(input$mybutton, {
print(getwd())
shinyalert(title = 'hello', imageUrl ="insert http url or local disk path/name.png", imageSize = "80x80")
for (i in 1:50000){ print(i) ### see if picture in message shows up before this code runs
}
})
}
shinyApp(ui = ui, server = server)
额外示例我如何使用 jscode 对其进行编码
swal5 = function(params) {
var defaultParams = {
title : null,
text : null,
type : null
};
params = shinyjs.getParams(params, defaultParams);
swal({title : params.title, text : params.text, type : params.type,
showCancelButton : true,
cancelButtonText : "No, cancel please!",
showConfirmButton : true,
confirmButtonText : "Yes, merge the files!",
closeOnCancel : true,
closeOnConfirm: false},
evalFunction = function(isConfirm){
if (isConfirm === true) {
var val1= 1;
Shiny.onInputChange("MergeRaw_OP", [val1, Math.random()]);}
});
};
您的代码(至少是第一个,没有尝试过第二个)实际上并不正确,并且有很多额外的代码没有做任何事情。无需加载shinyjs、shinydashboard,保存环境,sweetalertR
是错误的包。当我尝试 运行 该代码块的正确和最小版本时,它确实对我有用。
library(shinyalert)
library(shiny)
ui <- fluidPage(
useShinyalert(),
actionButton(inputId ="mybutton", "Run")
)
server <- function(input, output, session) {
observeEvent(input$mybutton, {
shinyalert(title = 'hello', imageUrl ="http://deanattali.com/img/deanimg.jpeg", imageSize = "80x80")
for (i in 1:50000){ print(i) }
})
}
shinyApp(ui = ui, server = server)
我运行遇到以下问题
使用 ShinyAlert * 如果我在消息中添加一个 imageUrl,如果它是一个互联网 url 地址,没问题,消息出现,图像立即出现,然后其他代码片段 运行 , 但 如果它是我硬盘上的图像,则会发生这种情况: 没有图像的消息打开 消息 运行s 之后的其他代码 然后图像出现..
我不知道为什么,我现在已经在 3 台不同的计算机上尝试过,并使用 js swal 方法对其进行了测试,同样的问题:
library(shiny)
library(sweetalertR)
library(shinyjs)
library(shinydashboard)
ui <- fluidPage(
shinyjs::useShinyjs(),
useShinyalert(),
textInput("expr", label = "Enter an R expression",
value = "bio",width="600px"),
actionButton(inputId ="mybutton", "Run")
)
server <- function(input, output, session) {
shinyEnv <- environment()
observeEvent(input$mybutton, {
print(getwd())
shinyalert(title = 'hello', imageUrl ="insert http url or local disk path/name.png", imageSize = "80x80")
for (i in 1:50000){ print(i) ### see if picture in message shows up before this code runs
}
})
}
shinyApp(ui = ui, server = server)
额外示例我如何使用 jscode 对其进行编码
swal5 = function(params) {
var defaultParams = {
title : null,
text : null,
type : null
};
params = shinyjs.getParams(params, defaultParams);
swal({title : params.title, text : params.text, type : params.type,
showCancelButton : true,
cancelButtonText : "No, cancel please!",
showConfirmButton : true,
confirmButtonText : "Yes, merge the files!",
closeOnCancel : true,
closeOnConfirm: false},
evalFunction = function(isConfirm){
if (isConfirm === true) {
var val1= 1;
Shiny.onInputChange("MergeRaw_OP", [val1, Math.random()]);}
});
};
您的代码(至少是第一个,没有尝试过第二个)实际上并不正确,并且有很多额外的代码没有做任何事情。无需加载shinyjs、shinydashboard,保存环境,sweetalertR
是错误的包。当我尝试 运行 该代码块的正确和最小版本时,它确实对我有用。
library(shinyalert)
library(shiny)
ui <- fluidPage(
useShinyalert(),
actionButton(inputId ="mybutton", "Run")
)
server <- function(input, output, session) {
observeEvent(input$mybutton, {
shinyalert(title = 'hello', imageUrl ="http://deanattali.com/img/deanimg.jpeg", imageSize = "80x80")
for (i in 1:50000){ print(i) }
})
}
shinyApp(ui = ui, server = server)