我正在我的服务器中创建一个矩阵.我想使用renderTable()在屏幕上输出这个矩阵.(我在服务器中创建它,因为它的长度(以及其他)取决于ui中的一些其他输入).
正如您将在下面看到的代码(或附图),出现的矩阵看起来并不好看:它是一个带有灰色边框,圆角等的矩阵.
所以问题是:有没有办法控制矩阵的外观?例如,我可能不想要边框,我可能希望rownames是斜体/粗体等...
shiny::runApp(
list(
ui = pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
helpText('This matrix is pretty ugly:')
),
mainPanel(
uiOutput('matrix')
)
)
,
server = function(input,output){
output$matrix <- renderTable({
matrix <- matrix(rep(1,6),nrow=3)
rownames(matrix) <- c('a','b','c')
matrix
})
}
)
)
Run Code Online (Sandbox Code Playgroud)

我需要在我的UI的多个选项卡中重复使用用户在第一个选项卡中提供的输入.
似乎不可能在服务器中使用renderUI并在我的不同选项卡中使用uiOutput调用其输出.这是一个可重现的代码
ui <- pageWithSidebar(
headerPanel("Hello !"),
sidebarPanel(
tabsetPanel(
tabPanel("a",
textInput(inputId = "xyz", label = "abc", value = "abc")),
tabPanel("b", uiOutput("v.xyz"))
,tabPanel("b", uiOutput("v.xyz"))
)
),
mainPanel())
server <- function(input,output){
output$v.xyz <- renderUI({
input$xyz
})
}
runApp(list(ui=ui,server=server))
Run Code Online (Sandbox Code Playgroud)
还有另一种方法来实现这一目标吗?
非常感谢任何建议.
我试图习惯在R中确定问题.我想在函数glm()内部调用函数,但它不起作用,显然是因为我没有设法修复函数assign()或作用的范围eval().
这是一个简化版本:
ao <- function (y, x, phi = seq (0,1,0.1), dataset, weights) {
logLikvector <- rep(0,length(phi)) # vector of zeros to be replaced thereafter
for (i in 1:length(phi)) { # loop to use glm()
fit <- glm (y ~ x, data = dataset, family = binomial, weights = weights)
logLikvector[i] <- logLik(fit) # get log likelihood
}
logLikvector
}
Run Code Online (Sandbox Code Playgroud)
现在我想在我的数据集上使用函数ao()
ao (y = Prop, x = Age, dataset = mydata, weights = Total) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用R闪亮来构建动态textInput.用户应该在文本字段中写入,然后按下添加按钮以填充另一个字段.但是,每次按下按钮时,所有字段都变为空,就像我必须提前定义我想要的字段数一样.任何帮助将非常感激.
谢谢
这是我的代码:
library(shiny)
shiny::runApp(list(
ui = pageWithSidebar(
headerPanel("test"),
sidebarPanel(
helpText("Alternatives list"),
verbatimTextOutput("summary")
),
mainPanel(
actionButton("obs","add"),
htmlOutput("selectInputs")
)
)
,
server = function(input,output){
observe({
if (input$obs == 0)
return()
isolate({
output$selectInputs <- renderUI({
if(!is.null(input$obs))
print("w")
w <- ""
for(i in 1:input$obs) {
w <- paste(w,textInput(paste("a",i,sep=""),paste("a",i,sep="")))
}
HTML(w)
})
output$summary <- renderPrint({
print("your Alternative are:")
for(i in 1:input$obs) {
print(
input[[sprintf("a%d",i)]]
)
}
})
outputOptions(output, 'selectInputs', suspendWhenHidden=FALSE)
})
})
}))
Run Code Online (Sandbox Code Playgroud) 我需要在我的界面中有多个标签,并且在每个标签中我都想使用conditionalPanel.正如您将在下面看到的可重现代码所示,conditionalPanel在第一个选项卡中工作,但在其他选项卡中不工作.
ui <- pageWithSidebar(
headerPanel("Hello !"),
sidebarPanel(
tabsetPanel(
tabPanel("a",
textInput(inputId = "A1", label = "1:", value = "A1"),
checkboxInput(inputId = "new_A2",
label = "Add another one",
value = FALSE),
conditionalPanel(
condition = "input.new_A2 == true",
textInput(inputId = "A2", label = "2:", value = "A2")
)),
tabPanel("b",
textInput(inputId = "B1", label = "1:", value = "C1"),
checkboxInput(inputId = "new_B2",
label = "Add another one",
value = FALSE),
conditionalPanel(
condition = "input.new_B2 == true",
textInput(inputId = "B2", label = "2:", value = …Run Code Online (Sandbox Code Playgroud) 如果我创建一个.htlm文件来定义一个actionButton,我如何为该按钮提供一个inputID(为了根据其值做其他事情)?
正如您将在.html中看到的那样,我尝试给它一个"id",但它不起作用.我相信实际给出一个inputID应该在ui.R文件中完成.
这是我的UI,服务器和.htlm文件:
1/UI:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("test"),
sidebarPanel(),
mainPanel(
includeHTML("static.html"),
uiOutput("x")
)
))
Run Code Online (Sandbox Code Playgroud)
2 /服务器:
shinyServer(function(input,output){
output$x<-renderUI(h4(input$button1))
})
Run Code Online (Sandbox Code Playgroud)
3/static.html
<p> <button class="btn btn-large btn-primary" type="button" id="button1"><i class="icon-star"></i>Large button</button>
</p>
Run Code Online (Sandbox Code Playgroud)
任何建议都将受到高度赞赏.
干杯
我想使用仅当前面的文本输入已完成(其初始值为“”)时才会出现的条件面板。正确定义条件面板中的条件的正确方法是什么?这是一个可重现的代码:
ui <- pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
textInput('test', "","")),
mainPanel(
conditionalPanel(condition = "input.test != "" ", #problem is here. I've tried many possibilities (such as input.test > 0) but none have worked
helpText("abc"))
)
)
server <- function(input,output){
}
runApp(list(ui=ui,server=server))
Run Code Online (Sandbox Code Playgroud)
任何意见/建议将不胜感激!
干杯
我需要在我的server.r这个类型的代码中的一行(基本上在服务器中我将安排来自ui.r的所有输入在列表中):
x<- list(input$field1,input$field2,input$field3, etc... until n=100)
x<- x[!= is.null(x)]
h4(x)
Run Code Online (Sandbox Code Playgroud)
代码在renderUI({})中使用.当我手动编写它时,它工作正常.但肯定有一种方法可以使用cat and paste(或其他函数)来更简洁地编写它.
使用以下内容不起作用,我不明白为什么:
x <- cat(paste("input$field", 1:100,",", sep = ""))
list(x)
Run Code Online (Sandbox Code Playgroud)
任何帮助/建议将受到高度赞赏
ps:我需要这个,因为我的输入是根据一个按钮生成的,因此可能是没有创建具有较大Id的字段,例如field99,我需要测试哪些字段已经创建.
干杯