我正在尝试使用 R 中精彩的 Shiny 库构建一个应用程序,我希望它为用户生成一些错误和状态消息。为了使其正常工作,我将条件面板与输出对象上的一些布尔标志结合使用,以呈现错误和状态消息的面板。根据文档,这个策略应该对我有用,但事实并非如此。
我将这个想法归结为一个简单的用户界面和服务器脚本,本质上我想做的是:
ui.R
library("shiny")
shinyUI(pageWithSidebar(
headerPanel('Hey There Guys!'),
sidebarPanel(
h4('Switch the message on and off!'),
actionButton('switch', 'Switch')
),
mainPanel(
conditionalPanel(condition = 'output.DISP_MESSAGE',
verbatimTextOutput('msg')
)
)
))
Run Code Online (Sandbox Code Playgroud)
服务器R
library('shiny')
shinyServer(function(input, output) {
output$DISP_MESSAGE <- reactive({input$switch %% 2 == 0})
output$msg <- renderPrint({print("Hey Ho! Let's Go!")})
})
Run Code Online (Sandbox Code Playgroud)
这里的想法是,按下按钮应该切换消息嘿嗬!我们走吧!开启和关闭。使用发布的代码,这是行不通的。在 Chrome 中加载页面时不会显示该消息,并且按下按钮不会执行任何操作。我有来自 CRAN 的最新版本的 Shiny。任何帮助将不胜感激!
我需要迭代生成器与自身的乘积,不包括对角线。我试图使用itertools.tee
相同的生成器两次
def pairs_exclude_diagonal(it):
i1, i2 = itertools.tee(it, 2)
for x in i1:
for y in i2:
if x != y:
yield (x, y)
Run Code Online (Sandbox Code Playgroud)
这不起作用
In [1]: for (x, y) in pairs_exclude_diagonal(range(3)):
...: print(x, y)
0 1
0 2
Run Code Online (Sandbox Code Playgroud)
从单个可迭代对象返回 n 个独立的迭代器。
这样做的正确方法是什么?
(我使用的是python3.6.1)