我正在测试脚本http://shiny.rstudio.com/articles/action-buttons.html(参见"模式1 - 命令")。
如果按下按钮"点击我"在网站上所以一切都很好 - 我们可以看到弹出菜单。
但是如果要将示例脚本复制到新的.R文件并运行它 - 没有出现弹出消息,则不会生成警告或错误消息(我的brouser是Google Chrome)。所以我对此感到困惑。
示例脚本:
library(shiny)
ui <- fluidPage(
tags$head(tags$script(src = "message-handler.js")),
actionButton("do", "Click Me")
)
server <- function(input, output, session) {
observeEvent(input$do, {
session$sendCustomMessage(type = 'testmessage',
message = 'Thank you for clicking')
})
}
shinyApp(ui, server)
答案 0 :(得分:3)
这应该有用,我给出了两个弹出警报的例子
1)使用标准from django.shortcuts import render, render_to_response
from django.core.context_processors import request, csrf
from django.views.decorators.csrf import csrf_protect
from login.models import login_table
def login(request):
c = {}
c.update(csrf(request))
firstname = request.POST.get('firstname')
lastname = request.POST.get('lastname')
email = request.POST.get('email')
username = request.POST.get('username')
password = request.POST.get('password')
gender = request.POST.get('test')
phonenumber = request.POST.get('phone')
country = request.POST.get('country')
data = login_table(first_name=firstname,last_name=lastname, email=email, user_name=username, password=password, gender=gender, phone=phonenumber,country=country)
data.save()
return render_to_response('log.html',c)
def login1(request):
c = {}
c.update(csrf(request))
us = request.POST.get('user_name')
pa = request.POST.get('password')
u = login_table.objects.get(user_name='user_name')
p = login_table.objects.get(password='password')
if us == u and pa == p:
response = render_to_response('content.html',c)
else:
response = render_to_response('failed.html', c)
return response
js
alert
2)使用rm(list = ls())
library(shiny)
ui <- fluidPage(
tags$head(tags$script(HTML('Shiny.addCustomMessageHandler("jsCode",function(message) {eval(message.value);});'))),
actionButton("do", "Click Me")
)
server <- function(input, output, session) {
observeEvent(input$do, {
js_string <- 'alert("Thank you for clicking");'
session$sendCustomMessage(type='jsCode', list(value = js_string))
})
}
shinyApp(ui, server)
包和shinyBS
弹出式广告
modal