使用 DT 包的按钮扩展,是否可以指定按钮下载 (1) 提供数据表的所有数据,或 (2) 仅可见页面上的数据。
以下是文档中的示例。
datatable(
iris, extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
)
Run Code Online (Sandbox Code Playgroud) 是否可以通过编辑DT :: DataTable来更新被动数据源?下面的代码是基于这个代码的变化,x被激活了.尝试在observeEvent中更改x时,问题就开始了.
有x反应的目的是我打算从外部数据库中获取它,然后编辑DT :: DataTable写回数据库,以便它与用户看到的内容保持同步(我很好那 - 它不是问题的一部分).
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
DTOutput('x1')
),
server = function(input, output, session) {
x = reactive({
df <- iris
df$Date = Sys.time() + seq_len(nrow(df))
df
})
output$x1 = renderDT(x(), selection = 'none', editable = TRUE)
proxy = dataTableProxy('x1')
observeEvent(input$x1_cell_edit, {
info = input$x1_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
# problem starts here
x()[i, j] <<- isolate(DT::coerceValue(v, x()[i, j]))
replaceData(proxy, x(), resetPaging = FALSE) # …Run Code Online (Sandbox Code Playgroud) 在谷歌地图中,搜索输入框会在用户输入时自动完成地址。有没有办法在 R Shiny 中通过访问自动完成值来做到这一点,以便与映射包一起使用?
有一个JavaScript方法在这里。我尝试在下面的代码中在 R Shiny 中使用此方法。SymbolixAU 指出使用google_map( search_box = TRUE )这是一个简单的解决方案。不幸的是,它在我的代码中不起作用,也因为我希望搜索框与地图分开。
下面的尝试在页面上按此顺序有文本输入my_address、文本输出copy_of_address和 googleway 地图my_map。
预期行为是让用户在 text input 中输入文本my_address,使用地址自动完成(这是有效的),地址将被复制到文本输出中copy_of_address(这仅显示输入的内容,而不是自动完成的版本),最后是地图以这个地址为中心。
看到输入框具有自动完成地址,但是地址和地图的副本仅使用用户输入文本。
在下面的代码中,替换MyKey为您的 google api 密钥(有时可以使用空字符串)。
library(shiny)
library(googleway)
key <- "MyKey"
set_key(key = key)
google_keys()
ui <- shiny::basicPage(
div(
textInput(inputId = "my_address", label = "")
,textOutput(outputId = "copy_of_address")
,HTML(paste0("
<script>
function initAutocomplete() {
new google.maps.places.Autocomplete(
(document.getElementById('my_address')),
{types: ['geocode']}
);
}
</script>
<script src='https://maps.googleapis.com/maps/api/js?key=", key,"&libraries=places&callback=initAutocomplete'
async …Run Code Online (Sandbox Code Playgroud) 在大约 100 个 excel 文件上使用 pandas read_excel - 有些文件很大 - 我想读取每个文件的前几行(标题和前几行数据)。
这不起作用,但说明了目标(例如读取 10 个数据行):
workbook_dataframe = pd.read_excel(workbook_filename, nrows = 10)
Run Code Online (Sandbox Code Playgroud)
这是我目前的解决方法:
workbook_dataframe = pd.read_excel(workbook_filename).head(10)
Run Code Online (Sandbox Code Playgroud)
解决方法的问题是它必须在取头之前读取整个 excel 文件。我也尝试过使用skiprows 和skip_footer 进行试验,给它提供只会产生错误的负数。
使用 Pandas 读取大的制表符分隔文件
df = pd.read_csv(file_path, sep='\t', encoding='latin 1', dtype = str, keep_default_na=False, na_values='')
Run Code Online (Sandbox Code Playgroud)
问题是有 200 列,第 3 列是偶尔带有换行符的文本。文本没有用任何特殊字符分隔。这些行被分成多行,数据进入错误的列。
每行都有固定数量的选项卡 - 这就是我所要做的。
遵循以下破折号快速入门指南,但在尝试运行python app.pyget消息时:
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Run Code Online (Sandbox Code Playgroud)
似乎是默认地址:http://127.0.0.1:8050/已被使用。如何更改默认端口,以便我可以使用它?
我试过在 google colab 上启用代码折叠
!jupyter nbextension enable codefolding/main
Run Code Online (Sandbox Code Playgroud)
然而,对colab的回应是
Enabling notebook extension codefolding/main...
- Validating: problems found:
- require? X codefolding/main
Run Code Online (Sandbox Code Playgroud)
是否可以在 colab 上进行代码折叠?
我想没有翻转盒的图像,我该怎么做?试过这个(也设置为NULL):
flipBox(
id = 1,
main_img = "",
header_img = "",
...
Run Code Online (Sandbox Code Playgroud)
我正在尝试上传图像,然后使用Shiny将其保存到服务器文件系统。
要上传,我发现
fileInput
Run Code Online (Sandbox Code Playgroud)
它创建一个包含图像详细信息和数据路径的data.frame。然后如何将其保存到远程服务器?
这类似于之前的累积和的帖子,它根据另一列中的值重置,除了我想限制总和以便它在达到最大值时也重置.例如,如果最大值为3:
> data.frame(x=rep(1,10),
+ y=c(0,0,1,0,0,0,0,1,0,0),
+ cum_sum_mod=c(1, 2, 1, 2, 3, 1, 2, 1, 2, 3))
x y cum_sum_mod
1 1 0 1
2 1 0 2
3 1 1 1
4 1 0 2
5 1 0 3
6 1 0 1
7 1 0 2
8 1 1 1
9 1 0 2
10 1 0 3
Run Code Online (Sandbox Code Playgroud)
cum_sum_modx列的总和直到达到最大值(3)或y列中的值为1.我想避免使用循环.