我有Shiny的问题,我不知道这是一个错误还是我错过了一些东西.我试图找到一个解决方案,但我似乎无法在网上找到这个问题的参考.
我有一个按下按钮时应该运行的功能,但它只在用户按下按钮后查看输出时才会运行.
这有点奇怪,所以我创建了一个最小的例子.我有两个标签.在第一个中,我选择一个数字(平均值),在第二个选项卡中,我绘制了该值的值.该按钮位于第一个选项卡中,但"create.plot"功能仅在转到tab2时才开始运行.为了清楚起见,我创建了这个'loading.div',它在函数运行时显示出来.
library(shiny)
library(shinyjs)
create.plot <- function(mean)
{
shinyjs::show('loading.div')
y <- rep(NA,10)
for(i in 1:10)
{
y[i] <- rnorm(1,mean=mean)
Sys.sleep(0.5)
}
shinyjs::hide('loading.div')
return(list(y=y, test='Now it runs from tab1'))
}
server <- function(input, output, session) {
run.function <- eventReactive(input$run,create.plot(input$mean))
output$plot.y <- renderPlot({
plot(run.function()[['y']])
})
output$test <- renderText({
run.function()[['test']]
})
}
ui <- fluidPage(shinyjs::useShinyjs(),
hidden(div(id='loading.div',h3('Loading..'))),
tabsetPanel(
tabPanel('tab1',
numericInput(inputId = 'mean',label='Mean', value=1),
actionButton(inputId = 'run', label='Run')
#,textOutput('test') ## Uncommenting this line, it works.
),
tabPanel('tab2',
plotOutput('plot.y'))
)
)
shinyApp(server=server,ui=ui)
Run Code Online (Sandbox Code Playgroud)
为了确保问题是用户在tab1时没有查看输出,我创建了一个测试字符串.如果取消注释该行,则问题是"修复":该功能在用户点击按钮后直接运行.但是,这只能起作用,因为他正在查看tab1中的输出.
这成为一个严重的问题,因为我有一个闪亮的仪表板,有很多标签.有带输入的选项卡和带输出的选项卡.我希望在单击按钮时运行该功能,但它仅在用户进入"输出"选项卡时运行.
这是一个已知的问题吗?有变通方法吗?
所以,我正在创建一个闪亮的应用程序,我想为使用 rhandsontable 生成的表中的一些行着色。
我正在关注这个非常好的教程:https : //jrowen.github.io/rhandsontable/
具体来说,我对这部分感兴趣:
library(rhandsontable)
DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
small = letters[1:10],
dt = seq(from = Sys.Date(), by = "days", length.out = 10),
stringsAsFactors = FALSE)
col_highlight = 2
row_highlight = c(5, 7)
rhandsontable(DF, col_highlight = col_highlight,
row_highlight = row_highlight,
width = 550, height = 300) %>%
hot_cols(renderer = "
function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
tbl = this.HTMLWidgets.widgets[0]
hcols = tbl.params.col_highlight
hcols = hcols …
Run Code Online (Sandbox Code Playgroud) 我正在开始使用 R 中的地图,但我面临着一个无法解决的问题。假设有以下脚本:
tmp_dir = tempdir()
url_data = "http://www.sharegeo.ac.uk/download/10672/50/English%20Government%20Office%20Network%20Regions%20(GOR).zip"
zip_file = sprintf("%s/shpfile.zip", tmp_dir)
download.file(url_data, zip_file)
unzip(zip_file, exdir = tmp_dir)
library(maptools)
gor=readShapeSpatial(sprintf('%s/Regions.shp', tmp_dir))
col=gray(gor$NUMBER/sum(gor$NUMBER))
col[5] = NA
plot(gor, col=col)
Run Code Online (Sandbox Code Playgroud)
我想要一种方法来将纹理添加到“col”向量上缺少数据的状态,而不是仅仅将其保留为白色。例如,在这种情况下,我正在寻找类似的东西:
如何向绘图的特定部分添加纹理,特别是在使用地图时?我读过像 add.texture 这样的函数,但我无法以如此灵活的方式使用它们。