我想为不同的标签显示不同的输入.所以我尝试构建一个包含多个tabPanel的页面.但是,我不能像下面这样:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Header"),
tabsetPanel(
tabPanel(
headerPanel("Tab 1"),
sidebarPanel(
selectInput("var", "Parametre", choices = c("1", "2", "3"))
),
mainPanel(
textOutput("text1")
)
),
tabPanel(
headerPanel("Tab 2"),
sidebarPanel(
selectInput("var", "Parametre", choices = c("21", "22", "23"))
),
mainPanel(
textOutput("text2")
)
)
)
))
Run Code Online (Sandbox Code Playgroud)
我怀疑这pageWithSidebar是导致问题的原因,但我无法在Google群组中找到替代方案.有没有办法用自己的侧边栏和主面板显示多个标签,还是应该为此创建不同的应用程序?
我正在努力学习在ruby中创建一个多类程序.我编写了一个Engine类和一些其他类,如city,street等,并且在将类名作为变量传递给其他类时遇到了问题.下面的代码抛出错误:"City.rb:15:in'intro':未定义的局部变量或方法游戏'for#(NameError)".我在某种程度上理解这个问题,但我不认为这个城市需要了解游戏对象的任何内容,我认为它只需要得到它并将其传回去.但显然我对如何在类之间传递变量(尤其是类名)有误解.我的设计出了什么问题?
#Game.rb
require './City.rb'
class Engine
def initialize(city_name, street_name, budget)
@city = City.new(city_name)
@city.read_name()
play(@city, :intro, self)
end
def play(place, next_step, engine)
while true
next_step = place.method(next_step).call(place, next_step, engine)
end
end
end
game = Engine.new("Casablanca", "Costanza Boulvard", 200)
#City.rb
class City
def initialize(city_name)
@city_name = city_name
end
def read_name()
puts <<-READ_NAME
You are in a city called "#{@city_name}".
READ_NAME
end
def intro(place, next_step, engine)
puts "...."
game.play(@street, :enter, engine)
end
end
Run Code Online (Sandbox Code Playgroud) 我想测试实例变量是否位于一系列数字中:
#part of the tested class
class Item
def initialize(value = 70 + rand(30))
@value = value
end
Run Code Online (Sandbox Code Playgroud)
我在minitest断言列表中尝试了断言,但它们没有用.我通过使用assert_in_delta解决了这个问题,如下所示:
#test_value.rb
class ValueTestCase < Test::Unit::TestCase
def test_if_value_in_range
item = Item.new
assert_in_delta(85, item.value, 15)
end
end
Run Code Online (Sandbox Code Playgroud)
但是想知道是否有正式的断言.