Skip to content

Commit

Permalink
Add Viewing list function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhimingYe committed Sep 1, 2024
1 parent c607b92 commit c542ecc
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: dotViewer
Title: View R Object in Shiny
Version: 0.1.0
Version: 0.1.2
Author: Zhiming Ye
Maintainer: Zhiming Ye <[email protected]>
Description: In RStudio, the Environment pane provides a good overview of
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(ViewDF)
export(ViewList)
export(ViewObj)
52 changes: 50 additions & 2 deletions R/Viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,56 @@ ViewObj<-function(x,selfExpr=F,pattern1=NULL,pattern2=NULL,pattern3=NULL,move=0,
pattern3<-".*?:"
}
if(!selfExpr){
.ViewInternal(capture.output(str(x,strict.width="cut")),pattern1 = pattern1,pattern2=pattern2,pattern3=pattern3,move=move,removeBlank=removeBlank)
.ViewInternal(capture.output(str(x,max.level = NA,list.len=100L,strict.width="cut")),pattern1 = pattern1,pattern2=pattern2,pattern3=pattern3,move=move,removeBlank=removeBlank)
}
else{
.ViewInternal(x,pattern1 = pattern1,pattern2=pattern2,pattern3=pattern3,move=move,removeBlank=removeBlank)
}
}
#' Viewing list in browser
#'
#' @param x A List
#'
#' @author Zhiming Ye
#' @return A shiny website
#' @export
#'
ViewList <- function(x){
if(!is.list(x)){
stop("Not A list!")
}
.ViewListInternal(x)
}

.ViewListInternal <- function(x){
require(shiny)
require(shinyTree)
require(shinyAce)

ui <- shinyUI(
pageWithSidebar(
titlePanel("dotViewer 0.1.0"),

sidebarPanel(
shinyTree("tree"),width = 10
),
mainPanel(
aceEditor("r_code",
mode = "r", # Set editor mode to R
theme = "textmate", # Set editor theme
value = capture.output(str(x,max.level = NA,list.len=100L,strict.width="cut")),
readOnly=T,
wordWrap=T,height="800px"),width = 10
)
))
server <- shinyServer(function(input, output, session) {
output$tree <- renderTree({
x
})

})
shinyApp(ui=ui,server = server)
}

.ViewInternal<-function(x,pattern1,pattern2,pattern3,move=0,removeBlank=T){
dt<-x
Expand Down Expand Up @@ -152,7 +196,7 @@ ViewObj<-function(x,selfExpr=F,pattern1=NULL,pattern2=NULL,pattern3=NULL,move=0,

ui <- shinyUI(
pageWithSidebar(
headerPanel("dotViewer 0.1.0"),
titlePanel("dotViewer 0.1.0"),

sidebarPanel(
shinyTree("tree"),width = 10
Expand Down Expand Up @@ -192,3 +236,7 @@ ViewObj<-function(x,selfExpr=F,pattern1=NULL,pattern2=NULL,pattern3=NULL,move=0,

shinyApp(ui = ui, server = server)
}
.onAttach<-function(libname,pkgname){
packageStartupMessage("\n***dotViewer***\nView DF using ViewDF, View Object using ViewObj, View List using ViewList\n=============\nAuthor:Zhiming Ye\n")
}
# attachment::att_amend_desc()
2 changes: 1 addition & 1 deletion man/ViewDF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/ViewList.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@

- **S4 Object Inspection**:

Easily inspect S4 objects' slots and structure, similar to the RStudio environment. ![](Figs/S4obj.jpg)
Easily inspect S4 objects' slots and structure, similar to the RStudio environment, by print `ViewObj(x)`.

![](Figs/S4obj.jpg)

- **Comprehensive Property Overview**:

dotViewer parses the output of the `str()` function to generate a detailed property map using `ShinyTree`, providing a clear and organized overview of an object’s structure.
dotViewer parses the output of the `str()` function to generate a detailed property map using `ShinyTree`, providing a clear and organized overview of an object’s structure.

![](Figs/s3obj.jpg)

- **S3 and Untested Object Compatibility**:

For objects like S3 and others that may not have been extensively tested, dotViewer offers an `AceEditor`-based editor. This editor allows for the preview of `str()` output with advanced features like syntax highlighting and search, enhancing your understanding of object structures, which are not supported in the default VSCode R extension.
For objects like S3 and others that may not have been extensively tested, dotViewer offers an `AceEditor`-based editor. This editor allows for the preview of `str()` output with advanced features like syntax highlighting and search, enhancing your understanding of object structures, which are not supported in the default VSCode R extension.

![](Figs/S3Tibble.jpg)

- **List Viewing**:

`ShinyTree` is based on list, you can use `ViewList` to view lists.

- **DT-Based Table Preview**:

When working over SSH connections, loading large tables into the VSCode front-end can potentially cause instability. dotViewer addresses this by providing a preview pane based on DT for table objects, ensuring a more stable experience.

![](Figs/DTExample.jpg)
![](Figs/DTExample.jpg)

- **Integrated with VSCode**:

Expand Down Expand Up @@ -90,6 +96,12 @@ Enjoy the convenience of RStudio’s object inspection capabilities within the p
```
dotViewer::ViewDF(x,n = 10000) # You can determine how many rows is passed to DT
```
3. **Viewing lists:**
```
dotViewer::ViewList(x)
```
## License
Expand Down

0 comments on commit c542ecc

Please sign in to comment.